jelhan / ember-local-storage-decorator

Decorator for Ember.js to read and persist data in localStorage
MIT License
22 stars 3 forks source link

fastboot support #5

Open lifeart opened 3 years ago

lifeart commented 3 years ago

https://github.com/jelhan/ember-local-storage-decorator/blob/6702fab573f14edf3391443c5bf84e9277e862d3/addon/index.js#L6

as I know, there is no window in fastboot, this logic could be moved to initializer

jelhan commented 3 years ago

Good catch. Need to add guards for FastBoot at all places at which we use either window.addEventListener or window.localStorage.

FastBoot documentation for addon author discusses two approaches:

  1. Optional chaining
  2. Using browser-only APIs

I would prefer the first. Don't want to split the code over multiple places.

Happy to accept a PR.

jelhan commented 1 year ago

I just noticed that FastBoot support is not as simple as expected. The decorator uses a global cache for local storage values: https://github.com/jelhan/ember-local-storage-decorator/blob/f80d55e0379a3ea285eb19500e3f2a454fd43bd3/addon/index.js#L3-L4

In FastBoot many application instances may run in parallel. To support FastBoot the caching implementation must be changed to cache the value per application instance.