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

BUG: On $reset if load the same values the Local Storage is clear. #281

Open
pdorgambide opened this issue Oct 3, 2018 · 1 comment
Open

Comments

@pdorgambide
Copy link

Bug: Browser storage mantein clear when $localstorage.$reset and try to load the same data.
$localstorage.$reset($localstorage); // Brower Local Storage are empty

The cause: On $reset the _last$storage variable is not clear and this make that on $apply the conditon always is true:
if (!angular.equals($storage, _last$storage))

Fix (suggested):

                  $reset: function(items) {
                            for (var k in $storage) {
                                '$' === k[0] || (delete $storage[k] && webStorage.removeItem(storageKeyPrefix + k));
                            }
                            _last$storage={}; 
                            return $storage.$default(items);
                        },
@dlemstra
Copy link

A hack that would work without changing the code would be:

const items = $localstorage;
$localstorage.$reset();
$localstorage.$apply(); // force storing the data to make sure _last$storage is overwritten.
$localstorage.$reset(items);

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

2 participants