// Action is: {type: 'GRAPH', myProp: {foo: 'bar', fuz: 'bus'}}
Batch Complete
Want to ensure the batch fires synchronously? You'll need to dispatch the batched action with one additional property: batchComplete.
import{createStore}from'redux';
importreducifyfrom'reducify';
importbatchMiddlewarefrom'redux-batch-actions';
conststore=createStore(
reducify({
"GRAPH":(state=0,action)=>action.data
}),
{},
applyMiddleware(batchMiddleware({
"GRAPH":true
}))
);
store.dispatch({
type:'GRAPH',
data:{foo:'bar'}
});
store.dispatch({
type:'GRAPH',
data:{fuz:'bus'}
});
store.dispatch({
type:'GRAPH',
batchComplete:true
});
// Action is: {type: 'GRAPH', data: {foo: 'bar', fuz: 'bus'}}
Batch Purge
Want to stop a batch from going out? Add batchPurge to an action and we'll clear it.
import{createStore}from'redux';
importreducifyfrom'reducify';
importbatchMiddlewarefrom'redux-batch-actions';
conststore=createStore(
reducify({
"GRAPH":(state=0,action)=>action.data
}),
{},
applyMiddleware(batchMiddleware({
"GRAPH":true
}))
);
store.dispatch({
type:'GRAPH',
data:{foo:'bar'}
});
store.dispatch({
type:'GRAPH',
data:{fuz:'bus'}
});
store.dispatch({
type:'GRAPH',
batchPurge:true
});
// No Action fired on current tick or next
Configuration
Tick
This batching relies on a tick function, that is - any function that we know will fire next time there is a javascript event loop.
By default, we use setTimeout([fn], 1) on the browser and process.nextTick([fn]) on the server. You can change this, however, by passing it in as an option when you declare your middleware.