Skip to content

Multiple optimistic reducers: only react to your own actions #55

@Buggytheclown

Description

@Buggytheclown

Feature request, i think it's important because:

  • optimization - we can skip some work
  • DX improvements - easy to debug optimistic slice, history have only valuable for the slice actions

I want to use multiple optimistic slices:

  • module isolation, code splitting: each module should work as isolated feature, we should be able to add it via 'lazy route' + 'replaceReducer'
  • optimization: don't want to store all actions (if we already have any BEGIN action), some payload may be to heavy

For example, if i use multiple 'optimistic' slices, i want each 'optimistic' enhancer react only on own actions:

const enhancedRootReducerNested = combineReducers({
  counter1: optimistic(counterReducer1), // 'INC_1'
  counter2: optimistic(counterReducer2), // 'INC_2'
})

test('only react on own BEGIN', t => {
  const begin0 = makeAction('INC_2', BEGIN, 0);
  const state1 = enhancedRootReducerNested(undefined, begin0);

  const expected = {
    counter1: {
      beforeState: undefined,
      history: [],
      current: 0
    },
    counter2: {
      beforeState: 0,
      history: [begin0],
      current: 1
    },
  };
  t.deepEqual(state1, expected);
});

Can be related with #54

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions