Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chenbin92 opened this issue May 8, 2020 · 8 comments
Open

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

chenbin92 opened this issue May 8, 2020 · 8 comments
Assignees

Comments

@chenbin92
Copy link
Collaborator

关联 issue ice-lab/icejs#279

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

@BestDI
Copy link

BestDI commented Jun 14, 2020

+1

@farrrr
Copy link
Contributor

farrrr commented Sep 17, 2020

如果自己硬幹的話,可以用 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 是可以不用...)

@chenbin92
Copy link
Collaborator Author

@luhc228 本周出方案

@chenbin92 chenbin92 added this to the 1.9.5 milestone Sep 21, 2020
@chenbin92 chenbin92 modified the milestones: 1.9.5, 1.11.0 Oct 19, 2020
@ClarkXia ClarkXia modified the milestones: 1.11.0, 1.12.0 Nov 10, 2020
@wangchongwei
Copy link

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

@dmyz
Copy link

dmyz commented Nov 10, 2021

有解决方案吗?

@ClarkXia ClarkXia removed this from the 1.12.0 milestone Nov 19, 2021
@xcore-oss
Copy link

挖坟了 持久化呢

@samaritanz
Copy link

现在这块有解决方案了吗

@preedomly
Copy link

请问有解决办法了吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants