ngxs-labs / async-storage-plugin

⏱ WIP: Async Storage Plugin
MIT License
34 stars 12 forks source link

Key option is not working #123

Open piernik opened 4 years ago

piernik commented 4 years ago

I think that key option is not working.

marcjulian commented 4 years ago

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

marcjulian commented 4 years ago

I updated the example project including a key and a migration

https://github.com/ngxs-labs/async-storage-plugin/blob/727b02f108612802688940eeb240b434d6c4d445/integration/app/app.module.ts#L33

Does that help you?

nvahalik commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

Hi Daniel,

We stopped using this plugin for now since it was causing too many issues. I am not able to provide any other feedback at this time.

On 2 Mar 2021, at 4:11, Daniel Mägerli wrote:

@nvahalik : Thanks for your inputs. We still couldn't manage to make the async storage work with keys, despite using the mentioned state tokens. 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".

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/ngxs-labs/async-storage-plugin/issues/123#issuecomment-788791027