Skip to content

Commit

Permalink
Merge a5677f2 into e45e3c4
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypercubed committed Jun 4, 2016
2 parents e45e3c4 + a5677f2 commit 78f4d85
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Initialize a new `barracks` instance.
Register a new action. Checks for circular dependencies when dispatching. The
callback receives the passed in data and a `wait(actions[, cb])` function that
can be used to call other actions internally. `wait()` accepts a single action
or an array of actions and an optional callback as the final argument.
or an array of actions and an optional callback as the final argument. Only
one callback can be added per action.

### dispatcher(action[, data])
Call an action and execute the corresponding callback. Alias:
Expand Down Expand Up @@ -96,7 +97,7 @@ pleased with, so I'll probably end up writing one in the near future.

## See Also
- [flux-standard-action](https://github.com/acdlite/flux-standard-action/) - human-friendly standard for Flux action objects
- [create-fsa](https://github.com/yoshuawuyts/create-fsa/) - create a flux-standard-action from a value
- [create-fsa](https://github.com/yoshuawuyts/create-fsa/) - create a flux-standard-action from a value
- [wayfarer](https://github.com/yoshuawuyts/wayfarer) - composable trie based router

## License
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function dispatcher () {
assert.equal(typeof cb, 'function')

actions[action] = actions[action] ? actions[action] : []
assert.equal(actions[action].length, 0, 'only on callback per action')
actions[action].push(cb)

return emit
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"coveralls": "~2.10.0",
"istanbul": "~0.2.10",
"standard": "^4.5.4",
"standard": "^7.1.2",
"tape": "^3.0.3",
"watch": "^0.16.0"
},
Expand Down
17 changes: 14 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@ test('.on() should assert input arguments', function (t) {
})

test('.on() should bind functions', function (t) {
t.plan(3)
t.plan(2)
const d = barracks()
const key = 'foo'
d.on(key, noop)
t.ok(Array.isArray(d._actions[key]), 'is array')
t.equal(d._actions[key].length, 1)
d.on('foo', noop)
t.equal(d._actions[key].length, 2)
})

test('.on() should only bind one function', function (t) {
t.plan(4)
const d = barracks()
const key = 'foo'
d.on(key, noop)
t.ok(Array.isArray(d._actions[key]), 'is array')
t.equal(d._actions[key].length, 1)
t.throws(function () {
d.on('foo', noop)
})
t.equal(d._actions[key].length, 1)
})

test('.emit() should assert action exists', function (t) {
Expand Down

0 comments on commit 78f4d85

Please sign in to comment.