Resolve a dependency graph of buffers.
Useful to manage multiple functions that rely on each other, and can recreate assets on the fly through means such as observing filesystem events.
var bufferGraph = require('buffer-graph')
var key = Buffer.from('my very cool graphing key')
var graph = bufferGraph(key)
graph.on('change', function (nodeName, edgeName, state) {
console.log(`${nodeName}:${edgeName} changed to ${state[name].hash}`)
})
// Triggers when graph.start() is called
graph.node('first', function (state, edge) {
console.log('initial state is', state.arguments)
edge('foo', Buffer.from('beep'))
setTimeout(function () {
edge('bar', Buffer.from('boop'))
}, 100)
})
// Triggers once first:foo and first:bar have been created. Retriggers if
// either dependency changes, and the state has a different hash.
graph.node('second', [ 'first:foo', 'first:bar' ], function (state, edge) {
console.log('first:foo', state.first.foo)
console.log('first:bar', state.first.bar)
edge('baz', Buffer.from('berp'))
})
graph.start({ hi: 'kittens' })
Emitted whenever an edge in the graph is updated.
Create a new buffer-graph
instance. Inherits from Node's
events.EventEmitter
module.
Create a new node in the buffer graph.
Start the graph. Can be passed arguments
which is set as state.arguments