Skip to content

Instantly share code, notes, and snippets.

@mzgoddard
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzgoddard/50d9d8ab4a86f8026dc1 to your computer and use it in GitHub Desktop.
Save mzgoddard/50d9d8ab4a86f8026dc1 to your computer and use it in GitHub Desktop.
Welder API Brainstorm 1

Welder exposes 3 major hooks and 1 minor one. Commands create a promise chain with the other 2 major hooks settle and reduce. Settle creates a hash of immutable data. Reduce operates in series on the same data. Settle and reduce are called with a name which expands by the command running it into a series of name sets to match against settle and reduce handles registered. If there are multiple handles registeredto the same matching name set, the minor hook, order, determines the sorting order of these handels.

  • command: performs a set of settle and reduce hooks
  • settle: returns immutable data optionally cached, errors are ok
  • reduce: operate on last value, error at the end is not ok, handlers can fix errors
  • order: used in settle and reduce to order multiple handles

'sync:graph' - matches in the high level order, handles on the same match rely on a 'order' handle to sort them. default 'order' is to warn and sort by generated name, causing registration order to determine order.

  • 'sync:graph:forward:before',
  • 'sync:graph:forward',
  • 'sync:graph:forward:after',
  • 'graph:forward:before',
  • 'graph:forward',
  • 'graph:forward:after,
  • 'sync:graph:before',
  • 'graph:before',
  • 'sync:graph'
  • 'graph',
  • 'graph:after',
  • 'sync:graph:after',
  • 'graph:reverse:before',
  • 'graph:reverse',
  • 'graph:reverse:after',
  • 'sync:graph:reverse:before',
  • 'sync:graph:reverse',
  • 'sync:graph:reverse:after'
function Welder() {}
Welder.prototype.settle
Welder.prototype.command
function WelderCommandInstance() {
this.welder;
}
WelderCommandInstance.prototype.settle = function(hook) {
return this.welder.settle(this.name + ':' + hook);
};
WelderCommandInstance.prototype.reduce = function(hook) {};
WelderCommandInstance.prototype.command
welder.register('command', 'sync', function(syncArg) {
// This is a WelderCommandInstance.
return this.promise()
.all([this.reduce('graph'), this.settle('load_registry')])
.get(0)
.then(this.reduce('solve_conflicts'))
.map(this.reduce('checkout'))
.map(this.settle('install'))
.then(this.reduce('verify'))
});
welder.register('reduce', 'graph', function(last) {
// WelderCommandInstance
this.command;
// Welder. Also accessible at this.command.welder.
this.welder;
if (this.command.name !== 'sync') { return; }
return last
.then()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment