Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
fixing issue with multiple driver instances
Browse files Browse the repository at this point in the history
  • Loading branch information
tymondesigns committed Jul 15, 2015
1 parent 68808d0 commit a7ec281
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 35 deletions.
6 changes: 0 additions & 6 deletions dist/angular-locker.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,6 @@
* @return {Locker}
*/
driver: function (driver) {
// no need to create a new instance if the driver is the same
if (driver === this._options.driver) return this;

return this.instance(angular.extend(this._options, { driver: driver }));
},

Expand All @@ -655,9 +652,6 @@
* @return {Locker}
*/
namespace: function (namespace) {
// no need to create a new instance if the namespace is the same
if (namespace === this._namespace) return this;

return this.instance(angular.extend(this._options, { namespace: namespace }));
},

Expand Down
2 changes: 1 addition & 1 deletion dist/angular-locker.min.js

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

2 changes: 1 addition & 1 deletion dist/angular-locker.min.js.map

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions src/angular-locker.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,6 @@
* @return {Locker}
*/
driver: function (driver) {
// no need to create a new instance if the driver is the same
if (driver === this._options.driver) return this;

return this.instance(angular.extend(this._options, { driver: driver }));
},

Expand All @@ -655,9 +652,6 @@
* @return {Locker}
*/
namespace: function (namespace) {
// no need to create a new instance if the namespace is the same
if (namespace === this._namespace) return this;

return this.instance(angular.extend(this._options, { namespace: namespace }));
},

Expand Down
29 changes: 8 additions & 21 deletions test/spec/angular-locker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ describe('angular-locker', function () {
locker.put('someKey', str);

expect( locker.get('someKey') ).toEqual(str);

locker.driver('session').put('sessionKey1', 1);
locker.driver('session').put('sessionKey2', 2);
locker.driver('local').put('localKey1', 1);
locker.driver('local').put('localKey2', 2);

expect(locker.driver('session').get('sessionKey2')).toEqual(2);

}));

it('should put a boolean into the locker', inject(function (locker) {
Expand Down Expand Up @@ -702,27 +710,6 @@ describe('angular-locker', function () {
expect( locker.driver('session').getDriver() ).toEqual($window.sessionStorage);
}));

it('should return the same instance if driver or namespace not changed', inject(function ($window, locker) {
expect( locker.getDriver() ).toEqual($window.localStorage);

var localInstance1 = locker;
var localInstance2 = locker.driver('local');
var sessionInstance = locker.driver('session');

expect( localInstance1 ).toEqual(localInstance2);
expect( localInstance1 ).not.toEqual(sessionInstance);
}));

it('should return the same instance if driver or namespace not changed', inject(function ($window, locker) {
expect( locker.getNamespace() ).toEqual('locker');

var defaultNamespace1 = locker;
var defaultNamespace2 = locker.namespace('locker');
var fooNamespace = locker.namespace('foo');

expect( defaultNamespace1 ).toEqual(defaultNamespace2);
expect( defaultNamespace2 ).not.toEqual(fooNamespace);
}));
});

});
Expand Down

0 comments on commit a7ec281

Please sign in to comment.