add function to second arg of `createAction` as a ownself reducer process
Closed this issue · 2 comments
nju33 commented
(createAction as CreateAction<ActionPayload, State>)('foo', (state, payload) => {
state.val = payload.val;
});
state
is Proxy it made by the immer
.
nju33 commented
import Flux from '@nju33/flux';
import {createStore} from 'redux';
interface AP {
foo: {
value: number;
};
bar: {
value: string;
}
}
const flux = new Flux<AP>(...);
flux.addAction('foo', (state, payload) => {...})
.addAction('bar', (state, payload) => {...})
.addAction('baz', (state, payload) => {...});
const store = createStore(flux.store);
const act = flux.act('foo', 'bar');
const actions = act({value: 1), {value: '123'});
// actions = {type: Symbol(), actions: [
// {type: Symbol(foo), payload: {value: 1}},
// {type: Symbol(bar), payload: {value: '123'}},
//]}
dispatch(actions);