Last active
December 1, 2015 15:02
-
-
Save timmfin/e71fd945be449fb03257 to your computer and use it in GitHub Desktop.
Silly example of using the readTree promise in the previous broccoli API
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; | |
} | |
MyPlugin.prototype.read = function(readTree) { | |
let outputPaths = []; | |
this.options.startCallback(); // first "hook" from plugin options | |
readTree(this.firstNode).then(firstNodeOutput => { | |
outputPaths.push(firstNodeOutput); | |
this.options.secondCallback(); // another "hook" from plugin options | |
return promiseMapSeries(this.otherNodes, (n) => { | |
return readTree(n).then(out => { | |
this.options.postEachOtherCallback(); // yet another "hook" from plugin options | |
return out; | |
}) | |
}); | |
}).then(([...otherNodesOutput]) => { | |
outputPaths = outputPaths.concat(otherNodesOutput); | |
this.options.finalCallback(); // a finished "hook" from plugin options | |
return whateverWeWantToDoWith(outputPaths); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment