Skip to content

Commit

Permalink
Refactor to improve bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 3, 2020
1 parent 2057ebb commit 1bc3f87
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,18 @@ module.exports = modifierFactory
// Turn `callback` into a child-modifier accepting a parent. See
// `array-iterate` for more info.
function modifierFactory(callback) {
return iteratorFactory(wrapperFactory(callback))
}

// Turn `callback` into a `iterator' accepting a parent.
function iteratorFactory(callback) {
return iterator

function iterator(parent) {
var children = parent && parent.children

if (!children) {
if (!parent || !parent.children) {
throw new Error('Missing children in `parent` for `modifier`')
}

iterate(children, callback, parent)
iterate(parent.children, iteratee, parent)
}
}

// Pass the context as the third argument to `callback`.
function wrapperFactory(callback) {
return wrapper

function wrapper(value, index) {
// Pass the context as the third argument to `callback`.
function iteratee(value, index) {
return callback(value, index, this)
}
}

0 comments on commit 1bc3f87

Please # to comment.