0

在我的状态下,我有两个用于打开和关闭搜索栏的操作,如何在它们之间切换。

`@Action(OpenSearchBar)
    OpenSearchBar({ patchState }: StateContext<GalleryStateModel>) {
        patchState({ isSearchBarOpen: true });
    }
    @Action(CloseSearchBar)
    CloseSearchBar({ patchState }: StateContext<GalleryStateModel>) {
        patchState({ isSearchBarOpen: false });
    }

`

4

1 回答 1

0
@Action( ToggleSearchInput )
toggleSearchInput(ctx: StateContext<GalleryStateModel>) {
    const state = ctx.getState();
    ctx.setState(
        produce(state, draft => {
            draft.isSearchBarOpen = !state.isSearchBarOpen;
        })
    );
}`
于 2018-07-10T06:15:57.880 回答