Last active
December 3, 2015 17:47
-
-
Save timmfin/4b9ce1dafa7325f14378 to your computer and use it in GitHub Desktop.
Another thought experiement on broccoli v1 changes to more easily hook into and/or compose inputNodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MyPlugin(inputNodes, options) { | |
this.options = options; | |
// In this example, let's say we need to do something special with the first | |
// inputNode as compared to the others. | |
[this.firstNode, ...this.otherNodes] = inputNodes; | |
this.firstNode.appendChildNode(this.options.startCallback); // pre-firstNode hook | |
this.wrapChildNode(0, this.options.secondCallback); // post-firstNode hook | |
// Callback after every "otherNode" | |
this.otherNodes.forEach((n, i) => this.wrapChildNode(i + 1, this.options.postEachOtherCallback)); | |
// Make `finalCallback` only get called after _all_ input nodes are fully finished | |
// using the little eventComposeHelper util (included below). A bit superficial | |
// but illustates needing to "hook" into the completion of X different nodes | |
this.appendChildNode(this.options.finalCallback); | |
Plugin.call(inputNodes, options); | |
} | |
MyPlugin.prototype.build = function() { | |
// Whatever else this plugin wants to do in its build ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment