redux-optimistic-ui
redux-optimistic-ui copied to clipboard
Ignore non-optimistic action from different slice
Hi, nice work, checked a few packages for optimistic updates and i think that redux-optimistic-ui is the best! But i have a few point before we can start using it.
combineReducers({
counter: optimistic(counter),
currency: currency,
})
- i have optimistic counter state that react on 'INC', 'DEC' action types
- i have actions from web-socket to update currency, 'SET_CURRENCY ' action types
I don't want 'SET_CURRENCY ' action to trigger "@@optimist: Possible memory leak detected."
I want to have the same history
after 'SET_CURRENCY' action
test('ignore action with no effect for optimistic reducer', t => {
const enhancedReducer = optimistic(rootReducer);
const begin0 = makeAction('INC', BEGIN, 0);
const nonOpt0 = {type: 'SET_CURRENCY'};
const state1 = enhancedReducer(undefined, begin0);
const actual = enhancedReducer(state1, nonOpt0);
const expected = {
beforeState: {counter: 0},
history: [begin0],
current: {counter: 1}
};
t.deepEqual(actual, expected);
});
Before we will add action to the history we can check if it affect our state:
const nextState = reducer(state.current, action);
if(type !== COMMIT && type !== REVERT && nextState === state.current) {
return state;
}