Skip to content

Commit 10619da

Browse files
committed
Merge branch 'pr/30'
2 parents f2ba6d4 + e4707d3 commit 10619da

File tree

4 files changed

+52
-18
lines changed

4 files changed

+52
-18
lines changed

dist/angular-localForage.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,19 @@
8181
// Directly adds a value to storage
8282
var setItem = function(key, value) {
8383
var deferred = $q.defer(),
84-
args = arguments;
84+
args = arguments,
85+
localCopy = angular.copy(value);
8586

86-
//avoid $promises attributes from value objects, if is there.
87-
if (angular.isObject(value) && angular.isDefined(value.$promise)) {
88-
delete value.$promise; //delete attribut from object structure.
87+
//avoid $promises attributes from value objects, if present.
88+
if (angular.isObject(localCopy) && angular.isDefined(localCopy.$promise)) {
89+
delete localCopy.$promise; //delete attribut from object structure.
8990
}
9091

91-
localforage.setItem(prefix() + key, value).then(function success() {
92+
localforage.setItem(prefix() + key, localCopy).then(function success() {
9293
if(notify.setItem) {
93-
$rootScope.$broadcast('LocalForageModule.setItem', {key: key, newvalue: value, driver: localforage.driver()});
94+
$rootScope.$broadcast('LocalForageModule.setItem', {key: key, newvalue: localCopy, driver: localforage.driver()});
9495
}
95-
deferred.resolve(value);
96+
deferred.resolve(localCopy);
9697
}, function error(data) {
9798
onError(data, args, setItem, deferred);
9899
});
@@ -292,4 +293,4 @@
292293
}
293294
}
294295
}]);
295-
})(window, window.angular, window.localforage);
296+
})(window, window.angular, window.localforage);

dist/angular-localForage.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular-localForage.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,19 @@
7474
// Directly adds a value to storage
7575
var setItem = function(key, value) {
7676
var deferred = $q.defer(),
77-
args = arguments;
77+
args = arguments,
78+
localCopy = angular.copy(value);
7879

79-
//avoid $promises attributes from value objects, if is there.
80-
if (angular.isObject(value) && angular.isDefined(value.$promise)) {
81-
delete value.$promise; //delete attribut from object structure.
80+
//avoid $promises attributes from value objects, if present.
81+
if (angular.isObject(localCopy) && angular.isDefined(localCopy.$promise)) {
82+
delete localCopy.$promise; //delete attribut from object structure.
8283
}
8384

84-
localforage.setItem(prefix() + key, value).then(function success() {
85+
localforage.setItem(prefix() + key, localCopy).then(function success() {
8586
if(notify.setItem) {
86-
$rootScope.$broadcast('LocalForageModule.setItem', {key: key, newvalue: value, driver: localforage.driver()});
87+
$rootScope.$broadcast('LocalForageModule.setItem', {key: key, newvalue: localCopy, driver: localforage.driver()});
8788
}
88-
deferred.resolve(value);
89+
deferred.resolve(localCopy);
8990
}, function error(data) {
9091
onError(data, args, setItem, deferred);
9192
});
@@ -285,4 +286,4 @@
285286
}
286287
}
287288
}]);
288-
})(window, window.angular, window.localforage);
289+
})(window, window.angular, window.localforage);

tests/angular-localForage.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,36 @@ describe('Module: LocalForageModule', function () {
129129
run('webSQLStorage');
130130
});
131131

132-
});
132+
it('service:setItem should strip $$hashKey from arrays used in ngRepeat', function() {
133+
var result = null;
134+
function run(driver) {
135+
return runs(function() {
136+
return myService.setDriver(driver).then(function() {
137+
return myService.clear().then(function() {
138+
return myService.setItem('myArray', [{$$hashKey: '00A', name:'Andrew Davis'}]).then(function() {
139+
return myService.getItem('myArray').then(function(data) {
140+
expect(data).toEqual([{name:'Andrew Davis'}]);
141+
}, function(res) {
142+
console.log(res);
143+
throw('Fail get item, driver = '+driver)
144+
});
145+
}, function(res) {
146+
console.log(res);
147+
throw('Fail set item, driver = '+driver)
148+
});
149+
}, function(res) {
150+
console.log(res);
151+
throw('Fail clear, driver = '+driver)
152+
})
153+
}, function() {
154+
throw('Fail set driver '+driver)
155+
})
156+
});
157+
}
158+
159+
run('asyncStorage');
160+
run('localStorageWrapper');
161+
run('webSQLStorage');
162+
});
163+
164+
});

0 commit comments

Comments
 (0)