我在打开和关闭搜索栏的状态下有两个动作,如何在它们之间进行切换。
`@Action(OpenSearchBar)
OpenSearchBar({ patchState }: StateContext<GalleryStateModel>) {
patchState({ isSearchBarOpen: true });
}
@Action(CloseSearchBar)
CloseSearchBar({ patchState }: StateContext<GalleryStateModel>) {
patchState({ isSearchBarOpen: false });
}
`
答案 0 :(得分:0)
@Action( ToggleSearchInput )
toggleSearchInput(ctx: StateContext<GalleryStateModel>) {
const state = ctx.getState();
ctx.setState(
produce(state, draft => {
draft.isSearchBarOpen = !state.isSearchBarOpen;
})
);
}`