Skip to content

Commit a983d54

Browse files
committed
signAsync
1 parent ed09c2b commit a983d54

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/dispatcher.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const defaultOptions = {
6464
customDispatch: getDelayedDispatch,
6565
isGossipType: isGossipType,
6666
verifyAsync: undefined,
67+
signAsync: undefined,
6768
}
6869

6970
export default class Dispatcher extends Scuttlebutt {
@@ -78,6 +79,7 @@ export default class Dispatcher extends Scuttlebutt {
7879
this._isGossipType = this.options.isGossipType
7980

8081
this._verifyAsync = this.options.verifyAsync
82+
this._signAsync = this.options.signAsync
8183

8284
// redux methods to wrap
8385
this._reduxDispatch = () => {
@@ -190,14 +192,9 @@ export default class Dispatcher extends Scuttlebutt {
190192
// we should ensure we don't send objects which will explode JSON.parse here
191193
// implemented over scuttlebutt class
192194
localUpdate(action) {
193-
if (process.env.NODE_ENV === 'development') {
194-
try {
195-
super.localUpdate(action)
196-
} catch (error) {
197-
throw new Error('Scuttlebutt couldn\'t dispatch', error)
198-
}
195+
if (this._signAsync) {
196+
this._signAsync(super.localUpdate.bind(this), action, this._reduxGetState)
199197
} else {
200-
// try our luck
201198
super.localUpdate(action)
202199
}
203200
}

test/dispatcher.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ tape('dispatcher({ signAsync })', function (t) {
150150

151151
// first call
152152
t.equal(dispatch.getCall(0).args[0].payload, payloads[0], 'called dispatch with valid action 1')
153-
t.equal(dispatch.getCall(0).args[0].signed, payloads[0], 'called dispatch with signed action 1')
153+
t.ok(dispatch.getCall(0).args[0].signed, 'called dispatch with signed action 1')
154154

155155
// second call
156156
t.equal(dispatch.getCall(1).args[0].payload, payloads[1], 'called dispatch with valid action 2')
157-
t.equal(dispatch.getCall(1).args[0].signed, payloads[0], 'called dispatch with signed action 2')
157+
t.ok(dispatch.getCall(1).args[0].signed, 'called dispatch with signed action 2')
158158

159159
t.equal(getState.callCount, 2, 'getState was called for each getHistory')
160160
t.end()

0 commit comments

Comments
 (0)