Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dist/angular-local-storage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* An Angular module that gives you access to the browsers local storage
* @version v0.1.5 - 2014-11-06
* @version v0.1.5 - 2014-11-26
* @link https://github.com/grevory/angular-local-storage
* @author grevory <greg@gregpike.ca>
* @license MIT License, http://www.opensource.org/licenses/MIT
Expand Down Expand Up @@ -413,6 +413,7 @@ angularLocalStorage.provider('localStorageService', function() {
var onKeyUpdated = function (event) {
if (event.key == deriveQualifiedKey(key)) {
scope[key] = getFromLocalStorage(key);
$rootScope.$broadcast('LocalStorageModule.notification.scopechanged', {key: key, storageType: self.storageType});
scope.$apply();
}
};
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-local-storage.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/angular-local-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ angularLocalStorage.provider('localStorageService', function() {
var onKeyUpdated = function (event) {
if (event.key == deriveQualifiedKey(key)) {
scope[key] = getFromLocalStorage(key);
$rootScope.$broadcast('LocalStorageModule.notification.scopechanged', {key: key, storageType: self.storageType});
scope.$apply();
}
};
Expand Down
21 changes: 21 additions & 0 deletions test/spec/localStorageSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,27 @@ describe('localStorageService', function() {
expect($rootScope.test).toEqual(testValue);
}));

iit('should broadcast an event when scope has been updated', inject(function ($rootScope, localStorageService, $window) {
localStorageService.bind($rootScope, 'test');
$rootScope.$digest();

// set the value in local storage mock to a value, then emit a changed event
var testValue = 'test';
$window.localStorage['ls.test'] = testValue;
var evt = document.createEvent('CustomEvent');
evt.key = 'ls.test';
evt.newValue = 'test value';
evt.initCustomEvent('storage', true, true, {
key: 'ls.test',
newValue: testValue
});
var spy = spyOn($rootScope, '$broadcast');
window.dispatchEvent(evt);
$rootScope.$digest();

expect($rootScope.$broadcast).toHaveBeenCalledWith('LocalStorageModule.notification.scopechanged', jasmine.any(Object));
}));

it('should be able to bind to scope using different key', inject(function($rootScope, localStorageService) {

localStorageService.set('lsProperty', 'oldValue');
Expand Down