funkensturm/ember-local-storage

Issue when using storageFor with native classes

danr1979 opened this issue · 3 comments

Hi.

We are trying to use the storageFor function in our Ember service, which uses native JS classes rather than EmberObject. I am doing the following to initialise:

export default class InitialisationService extends Service {
    localStorage = storageFor('user-settings');
    ...
}

and then setting values like so:

this.localStorage.brandingPrimaryColour = 'red';

but the values are not appearing in local storage.

Should ember-local-storage work with native classes or am I doing something wrong?

Thanks.

@danr1979 Were you able to resolve your issue (I'm guessing so since you closed this issue). I was curious what the problem was for you.

No, so I ended up writing my own native class ember service to interact with the browser's localstorage directly. It's not as fully featured as this addon but works with native classes.

@danr1979 that should work:

export default class InitialisationService extends Service {
  @storageFor('user-settings') localStorage;

  doSomething() {
    this.localStorage.get('someKey');
  }
}