Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore non-optimistic action from different slice #54

Open
Buggytheclown opened this issue Apr 4, 2021 · 0 comments
Open

Ignore non-optimistic action from different slice #54

Buggytheclown opened this issue Apr 4, 2021 · 0 comments

Comments

@Buggytheclown
Copy link

Buggytheclown commented Apr 4, 2021

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant