Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigation #259

Open
artuska opened this issue Feb 16, 2017 · 0 comments
Open

Investigation #259

artuska opened this issue Feb 16, 2017 · 0 comments

Comments

@artuska
Copy link

artuska commented Feb 16, 2017

After facing some mystical problems with the localStorage I looked into ngStorage plugin's code and... ugh, well:

  1. ngStorage copies whole local and session storage data into the $storage variable — well, I keep my localization JSON file into the local storage, I keep SVG icon sprite into the local storage, I keep all my XHR request responses into the session storage (because I use ETag) — and all this is stored in the $storage variable... this is not good

  2. $storage data synchronises with the real local/session storage every time $watcher executed — there is a debounce and there is angular.equals check but... c'mon... all this runs at every digest cycle

  3. $storage data synchronises with the real local/session storage every time data changed — so, every time I do something like $localStorage.foo = 'bar' whole $storage object writes itself to the local storage (remember, I keep there very big JSON file and SVG sprite)

  4. $storage data synchronizes with the real local/session storage when browser's tab is closed or reloaded — so, if I completely clear the local storage with some other plugin which does not use $localStorage or with vanilla JS (e.g. localStorage.clear()) and perform page refresh (e.g. location.reload())... whole local storage data mystically appears back in my local storage :)

  5. there is a storage event listener which listens for storage changes (e.g. if I write something to the local storage with vanilla JS), but there is an early return if the event has no key... so, if I clear the local storage (e.g. localStorage.clear()) event listener does not perform _last$storage = angular.copy($storage) and does not synchronize local storage with the $storage variable — so, ngStorage just does not know that local storage is empty already, no wonder why I got all my local storage data synchronized back after I cleared everything few moments ago :)

Well, I don't know what actually I want to say down here with all I've written above — maybe only that this plugin is only useful at very basic level, be careful to use it with other plugins or with vanilla JS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant