gsklee / ngStorage

localStorage and sessionStorage done right for AngularJS.
MIT License
2.33k stars 461 forks source link

Optimizing the apply function #231

Open KoenPasman opened 8 years ago

KoenPasman commented 8 years ago

I integrated a custom serializer and deserializer (in order to put gzip the content using lz-string lib). However, changing a certain setting caused all the keys to get reset in localStorage. Besides the entry that needs changing, also other entries are refreshed where this is not needed. Combine that with a rather slow/expensive compress function, this leads to performance degradation.

The PR checks if the key is actually changed before resetting it in the storageProvider.

KoenPasman commented 8 years ago

I'm not sure why the test is failing, it looks like the $apply function is used in other usecases as well. Maybe someone can shed some light on that?

KoenPasman commented 8 years ago

Allright! I managed to get the optimization working without breaking the tests. The problem was that the tempstorage reference always needs to be deleted, even if we don't persist the value into storage.