New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(postcss-zindex): refactor to drop dependencies #1096
Conversation
Replace uniqs and has with a map.
@@ -29,7 +29,7 @@ function pluginCreator(opts = {}) { | |||
return; | |||
} | |||
|
|||
cache.optimizeValues(); | |||
cache.optimizeValues(opts.startIndex || 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The start index is only used inside optimizeValues()
so I find passing it as an argument reduces indirection (instead of first storing it as an instance variable)
if (has(this._values, value)) { | ||
return this._values[value]; | ||
LayerCache.prototype.optimizeValues = function (startIndex) { | ||
const sortedValues = Array.from(this._values.keys()).sort(ascending); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assign to each z-index its rank in the sorted array.
LayerCache.prototype.optimizeValues = function () { | ||
this._values = uniq(this._values) | ||
.sort(ascending) | ||
.reduce(reduceValues.bind(this), {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the old code does its 'magic'. this._values
is initially an array, which then gets assigned to an object here.
return list; | ||
} | ||
|
||
LayerCache.prototype._findValue = function (value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole method is not needed anymore, since we can access the map by key directly.
Codecov Report
@@ Coverage Diff @@
## master #1096 +/- ##
==========================================
- Coverage 96.38% 96.37% -0.01%
==========================================
Files 115 115
Lines 3595 3589 -6
Branches 1060 1059 -1
==========================================
- Hits 3465 3459 -6
Misses 121 121
Partials 9 9
Continue to review full report at Codecov.
|
Less deps === less problems |
Replace uniqs and has with a map.
Updated algorithm
Compared to the previous version, it has a few advantages