Skip to content

Commit

Permalink
improve state and method chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
lipp committed Sep 2, 2016
1 parent 06247d0 commit 206f429
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/jet/peer/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Method.prototype.on = function (event, cb) {
} else {
this._dispatcher = this.createAsyncDispatcher(cb)
}
return this
} else {
throw new Error('event not available')
}
Expand Down
1 change: 1 addition & 0 deletions lib/jet/peer/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ State.prototype.on = function (event, cb) {
} else {
this._dispatcher = this.createAsyncDispatcher(cb)
}
return this
} else {
throw new Error('event not available')
}
Expand Down
10 changes: 10 additions & 0 deletions test/peer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ describe('Jet module', function () {
expect(state.path).to.be.a('function')
})

it('new jet.State().on returns self', function () {
var state = new jet.State(randomPath(), 123)
expect(state.on('set', function () {})).to.equal(state)
})

it('new jet.Method().on returns self', function () {
var method = new jet.Method(randomPath())
expect(method.on('call', function () {})).to.equal(method)
})

it('can add, fetch and set a state', function (done) {
var random = randomPath()
var state = new jet.State(random, 123)
Expand Down

0 comments on commit 206f429

Please sign in to comment.