Skip to content

Commit

Permalink
Merge branch 'release/0.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gias Kay Lee committed Jul 24, 2013
2 parents e41b498 + c1d66d7 commit 77cbd1e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngstorage",
"version": "0.2.0",
"version": "0.2.1",
"main": "./ngStorage.js",
"dependencies": {
"angular": "1.0.7"
Expand Down
36 changes: 17 additions & 19 deletions ngStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,62 +38,60 @@
var webStorage = $window[storageType],
$storage = {
$default: function(items) {
angular.forEach(items, function(v, k) {
angular.isDefined($storage[k]) || ($storage[k] = v);
});
for (var k in items) {
angular.isDefined($storage[k]) || ($storage[k] = items[k]);
}

return $storage;
},
$reset: function(items) {
for (var k in $storage) {
/^\$/.test(k) || delete $storage[k];
'$' === k[0] || delete $storage[k];
}

angular.forEach(items, function(v, k) {
$storage[k] = v;
});

return $storage;
return $storage.$default(items);
}
},
_last$storage;

for (var i = 0, k; k = webStorage.key(i); i++) {
$storage[k] = angular.fromJson(webStorage.getItem(k));
'ngStorage-' === k.slice(0, 10) && ($storage[k.slice(10)] = angular.fromJson(webStorage.getItem(k)));
}

_last$storage = angular.copy($storage);

$browser.addPollFn(function() {
if (!angular.equals($storage, _last$storage)) {
angular.forEach($storage, function(v, k) {
if (angular.isDefined(v) && !/^\$/.test(k)) {
if (angular.isDefined(v) && '$' !== k[0]) {

// Remove $$hashKey and other things that cannot be stringified
$storage[k] = angular.fromJson(angular.toJson(v));

webStorage.setItem(k, angular.toJson(v));
webStorage.setItem('ngStorage-' + k, angular.toJson(v));
}

delete _last$storage[k];
});

angular.forEach(_last$storage, function(v, k) {
webStorage.removeItem(k);
});
for (var k in _last$storage) {
webStorage.removeItem('ngStorage-' + k);
}

_last$storage = angular.copy($storage);

$rootScope.$digest();
$rootScope.$apply();
}
});

'localStorage' === storageType && angular.element($window).bind('storage', function(event) {
event.newValue ? $storage[event.key] = angular.fromJson(event.newValue) : delete $storage[event.key];
if ('ngStorage-' === event.key.slice(0, 10)) {
event.newValue ? $storage[event.key.slice(10)] = angular.fromJson(event.newValue) : delete $storage[event.key.slice(10)];

_last$storage = angular.copy($storage);
_last$storage = angular.copy($storage);

$rootScope.$digest();
$rootScope.$apply();
}
});

return $storage;
Expand Down

0 comments on commit 77cbd1e

Please sign in to comment.