async-storage-plugin icon indicating copy to clipboard operation
async-storage-plugin copied to clipboard

Key option is not working

Open piernik opened this issue 6 years ago • 6 comments

I think that key option is not working.

piernik avatar Oct 28 '19 13:10 piernik

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

marcjulian avatar Dec 12 '19 10:12 marcjulian

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?

marcjulian avatar Dec 12 '19 11:12 marcjulian

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 avatar Aug 05 '20 16:08 nvahalik

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.

nvahalik avatar Aug 13 '20 13:08 nvahalik

@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".

ghost avatar Mar 02 '21 10:03 ghost

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

nvahalik avatar Mar 04 '21 13:03 nvahalik