const authReducer = createReducer(
initialState,
on(startLogin, (state) => ({...state, isLogging: true})),
on(loginSuccessful, (state) => ({...state /*do sth other */})),
on(loginSuccessful, loginFailed, (state) => ({...state, isLogging: false}))
);在上面的示例中,我在多个操作之间共享逻辑(isLogging属性)。但是,当loginSuccesfull操作被分派时,只会触发其中一个reducers。
可以连接共享逻辑,而不是编写:
const authReducer = createReducer(
initialState,
on(startLogin, (state) => ({...state, isLogging: true})),
on(loginSuccessful, (state) => ({...state, isLogging: false /*do sth other */})),
on(loginFailed, (state) => ({...state, isLogging: false}))
);发布于 2019-10-06 18:54:04
这是不可能的(目前),只有相同动作类型的最后一个注册动作接收更新。
const authReducer = createReducer(
initialState,
on(startLogin, (state) => ({...state, isLogging: true})),
on(loginSuccessful, (state) => ({...state /*do sth other */})),
on(loginSuccessful, loginFailed, (state) => ({...state, isLogging: false})) // only this one will be triggered for loginSuccessful
);我们刚刚合并了一个PR,以使您的用例成为可能,这可能会在下一个版本中“退出”。
https://stackoverflow.com/questions/58251951
复制相似问题