ice icon indicating copy to clipboard operation
ice copied to clipboard

icejs内置的icestore,页面刷新数据会丢失

Open chenbin92 opened this issue 4 years ago • 8 comments

关联 issue https://github.com/ice-lab/icejs/issues/279

icejs内置的icestore状态管理方案,可以实现不同组件间通信,但是刷新页面后,数据会丢失,可否实现数据持久化配置?

chenbin92 avatar May 08 '20 13:05 chenbin92

+1

BestDI avatar Jun 14 '20 08:06 BestDI

如果自己硬幹的話,可以用 sessionStorage or localStorage 實做。

我自己的範例是這樣,可供參考,你可以針對你自己的情況選擇哪些資料要永久保存。

// models/user.ts
...
effects: (dispatch) => ({
  async authenticate({ nickname, password }: { nickname: string; password: string }) {
      const response = await userService.auth(nickname, password);
      const userData = response.data.data;

      sessionStorage.setItem('authUser', JSON.stringify(userData));
      dispatch.user.update(userData);
    },
    logout() {
      sessionStorage.removeItem('authUser');
      dispatch.user.update(DEFAULT_STATE);
    },
}),
...
// app.tsx
app: {
  getInitialData: async () => {
     const authSession = sessionStorage.getItem('authUser');

      if (authSession === null) {
        return {
          auth: {
            guest: true,
          },
        };
      }

      const authUser = JSON.parse(authSession);

      return {
        initialStates: {
          user: authUser,
        },
        auth: {
          ...authUser.roles,
          guest: authUser.status !== UserStatus.Active,
        },
      };
    },
  }
}

當然,如果 global state 自動在 icestore 能夠去設定 sessionStorage or localStorage 在寫入更新時自動同步更新這是更好了。(page state 是可以不用...)

farrrr avatar Sep 17 '20 03:09 farrrr

@luhc228 本周出方案

chenbin92 avatar Sep 21 '20 02:09 chenbin92

请问现在解决了吗? 现在是否支持数据持久化?

wangchongwei avatar Jul 23 '21 03:07 wangchongwei

有解决方案吗?

dmyz avatar Nov 10 '21 10:11 dmyz

挖坟了 持久化呢

xcore-oss avatar Dec 14 '21 07:12 xcore-oss

现在这块有解决方案了吗

samaritanz avatar Mar 30 '22 03:03 samaritanz

请问有解决办法了吗

preedomly avatar May 11 '22 07:05 preedomly