@@ -77,7 +77,7 @@ scuttlebutt({
7777 // the Primus object, can be switched out with any compatible transport.
7878 primus: (typeof window === ' object' && window .Primus ),
7979
80- // options passed through to the dispatcher
80+ // options passed through to the dispatcher (and their defaults)
8181 dispatcherOptions: {
8282 // the default will batch-reduce actions by the hundred, firing redux's
8383 // subscribe method on the last one, triggering the actual rendering on the
@@ -88,11 +88,52 @@ scuttlebutt({
8888 // returns whether an action's type should be broadcast to the network.
8989 // (returns false for @@INIT and internal @@scuttlebutt-prefixed action
9090 // types)
91- isGossipType: isGossipType (actionType), // (actionType) => bool
91+ isGossipType: isGossipType, // (actionType) => bool
92+
93+ // if specified, the specified function must call the callback with false or
94+ // true, depending on whether the action is valid.
95+ verifyAsync: false , // (callback, action, getStateHistory) => {}
9296 },
9397})
9498```
9599
100+ ### verifyAsync
101+
102+ The dispatcher option ` verifyAsync ` allows you to filter actions dispatched or
103+ gossiped about through scuttlebutt. You could validate an action's contents
104+ against a cryptographic signature, or rate limit, or an arbitrary rule:
105+
106+ ``` js
107+ import { UPDATE_ACTION } from ' redux-scuttlebutt'
108+
109+ function verifyAsync (callback , action , getStateHistory ) {
110+ const history = getStateHistory (),
111+ prevUpdate = history[history .length - 1 ],
112+ prevAction = prevUpdate && prevUpdate[UPDATE_ACTION ]
113+
114+ if (
115+ // if this message doesn't include an e
116+ action && action .payload
117+ && action .payload .indexOf (' e' ) === - 1
118+ // and the previously message didn't include an e
119+ && prevAction && prevAction && prevAction .payload
120+ && prevAction .payload .indexOf (' e' ) === - 1
121+ ) {
122+ callback (false )
123+ } else {
124+ callback (true )
125+ }
126+ }
127+ ```
128+
129+ The ` getStateHistory ` parameter returns an array of the form
130+ ` [UPDATE_ACTION, UPDATE_TIMESTAMP, UPDATE_SOURCE, UPDATE_SNAPSHOT] ` . These
131+ ` UPDATE_* ` constants are exported from scuttlebutt.
132+
133+ Note, if your verification is computationally expensive, you are responsible for
134+ throttling/delay (like you might for
135+ [ getDelayedDispatch] ( https://github.com/grrowl/redux-scuttlebutt/blob/4eb737a65e442f388cc1c69c917c8f7b1ee11271/src/dispatcher.js#L23 ) ).
136+
96137## conflict-free reducers
97138
98139While ` redux-scuttlebutt ` facilitates action sharing and enhancing the store,
0 commit comments