Middleware for syncing redux actions between app instances via pubnub.
import { createStore, applyMiddleware } from 'redux';
import createPubnubActionSyncerMiddleware from 'redux-pubnub-action-sync-middleware';
const pubnubMiddleware = createPubnubActionSyncerMiddleware({
publishKey: 'myPublishKey',
subscribeKey: 'mySubscribeKey',
});
const createStoreWithMiddleware = applyMiddleware(pubnubMiddleware)(createStore);
createPubnubActionSyncerMiddleware
takes an object parameter as input.
This is were to initialize the pubnub connection (pubnub docs)
In addition this object can set additional values for controlling the action syncing;
Possible values 'sender'
, 'receiver'
or 'both'
(default)
will only broadcast the actions taken with pubnub, but not apply any actions published by other instances.
will not broadcast actions taken in the instance, but will apply actions publiched by other instances.
will both broadcast and apply received actions.
'both'
Function taking an action and retuning a boolean value. The action will be sendt to the server if the function returns a truethy value.
(action) => true
Function taking an action and retuning a boolean value. The action will be applied dispatched to the store if the function returns a truethy value.
(action) => true
If mode is not set in code (see above) it can be set by query parameter. Use syncMode=sender
, syncMode=receiver
or syncMode=both
to control the syncing direction.
eg.
http://myapp?syncMode=sender