jbergstroem / buffer-graph

Resolve a dependency graph for buffer creation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

buffer-graph

npm version build status downloads js-standard-style

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.

Usage

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' })

Events

graph.on('change', name, state)

Emitted whenever an edge in the graph is updated.

API

graph = bufferGraph()

Create a new buffer-graph instance. Inherits from Node's events.EventEmitter module.

graph.node(name, [dependencies], fn(state, edge))

Create a new node in the buffer graph.

graph.start([arguments])

Start the graph. Can be passed arguments which is set as state.arguments

License

MIT

About

Resolve a dependency graph for buffer creation

License:MIT License


Languages

Language:JavaScript 100.0%