funkensturm / ember-local-storage

The addon provides a storageFor computed property that returns a proxy and persists the changes to localStorage or sessionStorage. It ships with an ember-data adapter.
https://www.funkensturm.com/ember-local-storage/
MIT License
218 stars 76 forks source link

Use factoryFor to get the storage factory #310

Closed svenpl closed 5 years ago

svenpl commented 5 years ago

This fixes an issue similar to #268, but with Ember 3.x.

fsmanuel commented 5 years ago

@svenpl Thank you for the PR. I'll review asap and release a new version.

fsmanuel commented 5 years ago

@svenpl I updated the ember-cli version. Can you rebase master and see if that fixes the tests?

svenpl commented 5 years ago

@fsmanuel Yes, I will do that.

fsmanuel commented 5 years ago

@svenpl thanks. I looked into the error and found out that the factoryFor().create() in ember 2.12.x sets __OWNER__ and __NAME_KEY__ which results in a premature save that overwrites the already stored data.

Could you update saveIfChanged in addon/helpers/utils.js:

// addon/helpers/utils.js
function saveIfChanged(key) {
  this._super.apply(this, arguments);

  // TODO: v2.0 - Remove workaround and drop support for 2.12.x
  // Ember 2.12.x sets __OWNER__ and __NAME_KEY__ on factoryFor().create()
  // which results in a premature save  hat overwrites the already stored data.
  if (/^__OWNER|NAME_KEY__/.test(key)) {
    return;
  }

  if (key !== '_isInitialContent') {
    this._save();
  }
}
fsmanuel commented 5 years ago

@svenpl released as v1.7.1. Thanks a lot!