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

Key option is not working #123

Open
piernik opened this issue Oct 28, 2019 · 6 comments
Open

Key option is not working #123

piernik opened this issue Oct 28, 2019 · 6 comments

Comments

@piernik
Copy link

piernik commented Oct 28, 2019

I think that key option is not working.

@marcjulian
Copy link
Collaborator

marcjulian commented Dec 12, 2019

Can you provide an example repository and explain the issue more detailed?

@marcjulian
Copy link
Collaborator

I updated the example project including a key and a migration

Does that help you?

@nvahalik
Copy link

nvahalik commented Aug 5, 2020

I had the same issue. The problem here is that you must use a state token or a string rather than pass in the StateModel that you might use with the selector.

In other words:

NgxsModule.forRoot([
      AccountSettingsState,
]),

Works for the NgxsModule import. But it won't work for the plugin:

NgxsAsyncStoragePluginModule.forRoot(IonicAsyncStorageService, {
  key: [
    AccountSettingsState, // will not work
    ACCOUNT_SETTING_STATE_TOKEN, // will work
  ]}),

Later update: My problem was that I was using a StateToken for the name in the @State decorator. This was not supported. When changing from a token to a regular string name, using the StateClass worked as expected.

@nvahalik
Copy link

Also, I might add that if you are using a StateToken as the name parameter, this won't work either. See #158 for a fix.

@ghost
Copy link

ghost commented Mar 2, 2021

@nvahalik : Thanks for your inputs. We still couldn't manage to make the async storage work with keys, despite using the mentioned state tokens. Neither does it work when using just the state class within the "key" array. Can you maybe point us to the right direction? Thanks in advance!

App Module

NgxsAsyncStoragePluginModule.forRoot(CustomStateStorageClass,
      {
        key: [
          // --- persistent ---
          SOME_STATE_TOKEN,

State

const STATE_NAME = "someStateName";
export const SOME_STATE_TOKEN = new StateToken<SomeStateModel>(STATE_NAME);
const DEFAULT_STATE: SomeStateModel = {
  someContent: []
};

@State<SomeStateModel>({
  name: STATE_NAME,
  defaults: DEFAULT_STATE,
})

PS: In CustomStateStorageClass we're using the Storage Module from Ionic, which is working perfectly fine when not using "key".

@nvahalik
Copy link

nvahalik commented Mar 4, 2021 via email

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

No branches or pull requests

3 participants