Bug fixes and code cleanup
With a lot of help from @robinnorth
This commit is contained in:
@@ -3,6 +3,8 @@ var forEachEls = require("./foreach-els")
|
||||
var defaultSwitches = require("./switches")
|
||||
|
||||
module.exports = function(switches, switchesOptions, selectors, fromEl, toEl, options) {
|
||||
var switchesQueue = [];
|
||||
|
||||
selectors.forEach(function(selector) {
|
||||
var newEls = fromEl.querySelectorAll(selector)
|
||||
var oldEls = toEl.querySelectorAll(selector)
|
||||
@@ -25,14 +27,17 @@ module.exports = function(switches, switchesOptions, selectors, fromEl, toEl, op
|
||||
this.log("newEl", newEl, "oldEl", oldEl)
|
||||
}
|
||||
|
||||
this.state.numPendingSwitches++
|
||||
var callback = (switches[selector]) ?
|
||||
switches[selector].bind(this, oldEl, newEl, options, switchesOptions[selector]) :
|
||||
defaultSwitches.outerHTML.bind(this, oldEl, newEl, options)
|
||||
|
||||
if (switches[selector]) {
|
||||
switches[selector].bind(this)(oldEl, newEl, options, switchesOptions[selector])
|
||||
}
|
||||
else {
|
||||
defaultSwitches.outerHTML.bind(this)(oldEl, newEl, options)
|
||||
}
|
||||
switchesQueue.push(callback)
|
||||
}, this)
|
||||
}, this)
|
||||
|
||||
this.state.numPendingSwitches = switchesQueue.length
|
||||
|
||||
switchesQueue.forEach(function(queuedSwitch) {
|
||||
queuedSwitch()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user