According to #1734 there is no consistent way to reuse actions without some "extra job" and compromises.
Add an extra field to Action interface, something like baseType.
For empty and props ActionCreators add an ability to pass an optional argument.
As a result of creator's function call, we should have an object like this:
{
type: context + type,
baseType: type
}
For compare incoming actions on and ofType should use baseType at first and a type as fallback
const foo = createAction('FOO');
const bar = createAction('BAR', props<{foo: number}>());
...
createReducer(
initialState,
on(foo, bar, (state) => ({...state, modifyed: true}))
);
....
createEffect(() =>
this.actions$.pipe(
ofType(foo, bar),
switchMap(_ => this.foobar())
),
{ dispatch: false }
);
...
this.store.dispatch(foo());
this.store.dispatch(foo('FOO CONTEXT'));
this.store.dispatch(bar({foo: 33}));
this.store.dispacth(bar({foo: 22}, 'BAR CONTEXT'));
I expect that reducer and effect will trigger for every action and action log looks like
[FOO CONTEXT]FOO
BAR
[BAR CONTEXT]BAR
[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No
@vmotornyi thanks for the issue. We are encouraging not to reuse actions. It is very easy to create them.
Also, we do not plan to split the type and will continue to _log_ (in redux-devtools) and _handle_ actions (in effects/reducers) by the same type property.
Personally, I feel it would be very very hard to track the actions with the split.
Most helpful comment
@vmotornyi thanks for the issue. We are encouraging not to reuse actions. It is very easy to create them.
Also, we do not plan to split the
typeand will continue to _log_ (in redux-devtools) and _handle_ actions (in effects/reducers) by the sametypeproperty.Personally, I feel it would be very very hard to track the actions with the split.