ng2-webstorage
Advanced tools
Comparing version 1.4.3 to 1.5.0
@@ -277,41 +277,80 @@ (function (global, factory) { | ||
var WebStorage = function WebStorageDecorator(webSKey, sType) { | ||
var WebstorageConfig = (function () { | ||
function WebstorageConfig(config) { | ||
this.prefix = LIB_KEY; | ||
this.separator = LIB_KEY_SEPARATOR; | ||
if (config && config.prefix !== undefined) { | ||
this.prefix = config.prefix; | ||
} | ||
if (config && config.separator !== undefined) { | ||
this.separator = config.separator; | ||
} | ||
} | ||
return WebstorageConfig; | ||
}()); | ||
function WebStorage(webSKey, sType) { | ||
return function (targetedClass, raw) { | ||
var key = webSKey || raw; | ||
Object.defineProperty(targetedClass, raw, { | ||
get: function () { | ||
var sKey = KeyStorageHelper.genKey(key); | ||
return WebStorageHelper.retrieve(sType, sKey); | ||
}, | ||
set: function (value) { | ||
var sKey = KeyStorageHelper.genKey(key); | ||
this[sKey] = value; | ||
WebStorageHelper.store(sType, sKey, value); | ||
} | ||
}); | ||
WebStorageDecorator(webSKey, STORAGE.local, targetedClass, raw); | ||
}; | ||
}; | ||
} | ||
var LocalStorage = function LocalStorageDecorator(webstorageKey) { | ||
return WebStorage(webstorageKey, STORAGE.local); | ||
}; | ||
function WebStorageDecorator(webSKey, sType, targetedClass, raw) { | ||
var key = webSKey || raw; | ||
Object.defineProperty(targetedClass, raw, { | ||
get: function () { | ||
var sKey = KeyStorageHelper.genKey(key); | ||
return WebStorageHelper.retrieve(sType, sKey); | ||
}, | ||
set: function (value) { | ||
var sKey = KeyStorageHelper.genKey(key); | ||
this[sKey] = value; | ||
WebStorageHelper.store(sType, sKey, value); | ||
} | ||
}); | ||
} | ||
var SessionStorage = function SessionStorageDecorator(webstorageKey) { | ||
return WebStorage(webstorageKey, STORAGE.session); | ||
}; | ||
function LocalStorage(webSKey) { | ||
return function (targetedClass, raw) { | ||
WebStorageDecorator(webSKey, STORAGE.local, targetedClass, raw); | ||
}; | ||
} | ||
function SessionStorage(webSKey) { | ||
return function (targetedClass, raw) { | ||
WebStorageDecorator(webSKey, STORAGE.session, targetedClass, raw); | ||
}; | ||
} | ||
var WEBSTORAGE_CONFIG = new _angular_core.OpaqueToken('WEBSTORAGE_CONFIG'); | ||
var Ng2Webstorage = (function () { | ||
function Ng2Webstorage(ngZone) { | ||
function Ng2Webstorage(ngZone, config) { | ||
this.ngZone = ngZone; | ||
if (config) { | ||
KeyStorageHelper.setStorageKeyPrefix(config.prefix); | ||
KeyStorageHelper.setStorageKeySeparator(config.separator); | ||
} | ||
this.initStorageListener(); | ||
} | ||
Ng2Webstorage.forRoot = function (_a) { | ||
var _b = _a === void 0 ? { prefix: LIB_KEY, separator: LIB_KEY_SEPARATOR } : _a, prefix = _b.prefix, separator = _b.separator; | ||
KeyStorageHelper.setStorageKeyPrefix(prefix); | ||
KeyStorageHelper.setStorageKeySeparator(separator); | ||
return { ngModule: Ng2Webstorage, providers: [] }; | ||
Ng2Webstorage.forRoot = function (config) { | ||
return { | ||
ngModule: Ng2Webstorage, | ||
providers: [ | ||
{ | ||
provide: WEBSTORAGE_CONFIG, | ||
useValue: config | ||
}, | ||
{ | ||
provide: WebstorageConfig, | ||
useFactory: provideConfig, | ||
deps: [ | ||
WEBSTORAGE_CONFIG | ||
] | ||
} | ||
] | ||
}; | ||
}; | ||
Ng2Webstorage.prototype.initStorageListener = function () { | ||
var _this = this; | ||
if (window) | ||
if (window) { | ||
window.addEventListener('storage', function (event) { return _this.ngZone.run(function () { | ||
@@ -321,2 +360,3 @@ var storage = window.sessionStorage === event.storageArea ? STORAGE.session : STORAGE.local; | ||
}); }); | ||
} | ||
}; | ||
@@ -333,7 +373,13 @@ Ng2Webstorage.decorators = [ | ||
{ type: _angular_core.NgZone, }, | ||
{ type: WebstorageConfig, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Inject, args: [WebstorageConfig,] },] }, | ||
]; }; | ||
return Ng2Webstorage; | ||
}()); | ||
function provideConfig(config) { | ||
return new WebstorageConfig(config); | ||
} | ||
function configure(_a) { | ||
var _b = _a === void 0 ? { prefix: LIB_KEY, separator: LIB_KEY_SEPARATOR } : _a, prefix = _b.prefix, separator = _b.separator; | ||
/*@Deprecation*/ | ||
console.warn('[ng2-webstorage:deprecation] The configure method is deprecated since the v1.5.0, consider to use forRoot instead'); | ||
KeyStorageHelper.setStorageKeyPrefix(prefix); | ||
@@ -343,7 +389,11 @@ KeyStorageHelper.setStorageKeySeparator(separator); | ||
exports.WEBSTORAGE_CONFIG = WEBSTORAGE_CONFIG; | ||
exports.Ng2Webstorage = Ng2Webstorage; | ||
exports.provideConfig = provideConfig; | ||
exports.configure = configure; | ||
exports.WebstorageConfig = WebstorageConfig; | ||
exports.LocalStorage = LocalStorage; | ||
exports.SessionStorage = SessionStorage; | ||
exports.WebStorage = WebStorage; | ||
exports.WebStorageDecorator = WebStorageDecorator; | ||
exports.WebStorageService = WebStorageService; | ||
@@ -350,0 +400,0 @@ exports.LocalStorageService = LocalStorageService; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define(["exports","@angular/core"],t):t(e.ng2Webstorage=e.ng2Webstorage||{},e.ng.core)}(this,function(e,t){"use strict";function r(e){var t=void 0===e?{prefix:i,separator:s}:e,r=t.prefix,n=t.separator;l.setStorageKeyPrefix(r),l.setStorageKeySeparator(n)}var n;!function(e){e[e.local=0]="local",e[e.session=1]="session"}(n||(n={}));var o,i="ng2-webstorage",s="|",a=(o={},o[n.local]="local",o[n.session]="session",o),c=i,u=s,l=function(){function e(){}return e.isManagedKey=function(e){return 0===e.indexOf(c+u)},e.retrieveKeysFromStorage=function(e){return Object.keys(e).filter(function(e){return 0===e.indexOf(c)})},e.genKey=function(e){if("string"!=typeof e)throw Error("attempt to generate a storage key with a non string value");return""+c+u+e.toString().toLowerCase()},e.setStorageKeyPrefix=function(e){void 0===e&&(e=i),c=e},e.setStorageKeySeparator=function(e){void 0===e&&(e=s),u=e},e}(),g=function(){function e(){}return e.observe=function(e,r){var n=this.genObserverKey(e,r);return n in this.observers?this.observers[n]:this.observers[n]=new t.EventEmitter},e.emit=function(e,t,r){var n=this.genObserverKey(e,t);n in this.observers&&this.observers[n].emit(r)},e.genObserverKey=function(e,t){return e+"|"+t},e.observers={},e}(),f=function(){function e(){}return e.isSecuredField=function(t){return!!~e.securedFields.indexOf(t)},e.getStorage=function(t){return this.mockStorages[t]||(this.mockStorages[t]=e.generateStorage()),this.mockStorages[t]},e.generateStorage=function(){var t={};return Object.defineProperties(t,{setItem:{writable:!1,enumerable:!1,configurable:!1,value:function(t,r){e.isSecuredField(t)||(this[t]=r)}},getItem:{writable:!1,enumerable:!1,configurable:!1,value:function(t){return e.isSecuredField(t)?null:this[t]||null}},removeItem:{writable:!1,enumerable:!1,configurable:!1,value:function(t){e.isSecuredField(t)||delete this[t]}},length:{enumerable:!1,configurable:!1,get:function(){return Object.keys(this).length}}}),t},e.securedFields=["setItem","getItem","removeItem","length"],e.mockStorages={},e}(),v=function(){function e(){}return e.store=function(e,t,r){this.getStorage(e).setItem(t,JSON.stringify(r)),this.cached[e][t]=r,g.emit(e,t,r)},e.retrieve=function(t,r){return this.cached[t][r]?this.cached[t][r]:this.cached[t][r]=e.retrieveFromStorage(t,r)},e.retrieveFromStorage=function(e,t){var r=null;try{r=JSON.parse(this.getStorage(e).getItem(t))}catch(e){console.warn("invalid value for "+t)}return r},e.refresh=function(t,r){if(l.isManagedKey(r)){var n=e.retrieveFromStorage(t,r);null!=n&&n!==this.cached[t][r]&&(this.cached[t][r]=n,g.emit(t,r,n))}},e.clearAll=function(e){var t=this,r=this.getStorage(e);l.retrieveKeysFromStorage(r).forEach(function(n){r.removeItem(n),delete t.cached[e][n],g.emit(e,n,null)})},e.clear=function(e,t){this.getStorage(e).removeItem(t),delete this.cached[e][t],g.emit(e,t,null)},e.getStorage=function(e){return this.isStorageAvailable(e)?this.getWStorage(e):f.getStorage(e)},e.getWStorage=function(e){var t;switch(e){case n.local:t=localStorage;break;case n.session:t=sessionStorage;break;default:throw Error("invalid storage type")}return t},e.isStorageAvailable=function(e){if("boolean"==typeof this.storageAvailability[e])return this.storageAvailability[e];var t=!0,r=this.getWStorage(e);if("object"==typeof r)try{r.setItem("test-storage","foobar"),r.removeItem("test-storage")}catch(e){t=!1}else t=!1;return t||console.warn(a[e]+" storage unavailable, Ng2Webstorage will use a fallback strategy instead"),this.storageAvailability[e]=t},e.cached=(t={},t[n.local]={},t[n.session]={},t),e.storageAvailability=(r={},r[n.local]=null,r[n.session]=null,r),e;var t,r}(),h=function(){function e(e){void 0===e&&(e=null),this.sType=e,this.sType=e}return e.prototype.store=function(e,t){var r=l.genKey(e);v.store(this.sType,r,t)},e.prototype.retrieve=function(e){var t=l.genKey(e);return v.retrieve(this.sType,t)},e.prototype.clear=function(e){e?v.clear(this.sType,l.genKey(e)):v.clearAll(this.sType)},e.prototype.observe=function(e){var t=l.genKey(e);return g.observe(this.sType,t)},e}(),y=function(e,t){function r(){this.constructor=e}for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)},p=function(e){function r(){e.call(this,n.local)}return y(r,e),r.decorators=[{type:t.Injectable}],r.ctorParameters=function(){return[]},r}(h),d=function(e,t){function r(){this.constructor=e}for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)},S=function(e){function r(){e.call(this,n.session)}return d(r,e),r.decorators=[{type:t.Injectable}],r.ctorParameters=function(){return[]},r}(h),b=function(e,t){return function(r,n){var o=e||n;Object.defineProperty(r,n,{get:function(){var e=l.genKey(o);return v.retrieve(t,e)},set:function(e){var r=l.genKey(o);this[r]=e,v.store(t,r,e)}})}},m=function(e){return b(e,n.local)},w=function(e){return b(e,n.session)},K=function(){function e(e){this.ngZone=e,this.initStorageListener()}return e.forRoot=function(t){var r=void 0===t?{prefix:i,separator:s}:t,n=r.prefix,o=r.separator;return l.setStorageKeyPrefix(n),l.setStorageKeySeparator(o),{ngModule:e,providers:[]}},e.prototype.initStorageListener=function(){var e=this;window&&window.addEventListener("storage",function(t){return e.ngZone.run(function(){var e=window.sessionStorage===t.storageArea?n.session:n.local;v.refresh(e,t.key)})})},e.decorators=[{type:t.NgModule,args:[{declarations:[],providers:[S,p],imports:[]}]}],e.ctorParameters=function(){return[{type:t.NgZone}]},e}();e.Ng2Webstorage=K,e.configure=r,e.LocalStorage=m,e.SessionStorage=w,e.WebStorage=b,e.WebStorageService=h,e.LocalStorageService=p,e.SessionStorageService=S,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define(["exports","@angular/core"],t):t(e.ng2Webstorage=e.ng2Webstorage||{},e.ng.core)}(this,function(e,t){"use strict";function r(e,t){return function(t,r){o(e,c.local,t,r)}}function o(e,t,r,o){var n=e||o;Object.defineProperty(r,o,{get:function(){var e=h.genKey(n);return S.retrieve(t,e)},set:function(e){var r=h.genKey(n);this[r]=e,S.store(t,r,e)}})}function n(e){return function(t,r){o(e,c.local,t,r)}}function i(e){return function(t,r){o(e,c.session,t,r)}}function s(e){return new I(e)}function a(e){var t=void 0===e?{prefix:l,separator:f}:e,r=t.prefix,o=t.separator;console.warn("[ng2-webstorage:deprecation] The configure method is deprecated since the v1.5.0, consider to use forRoot instead"),h.setStorageKeyPrefix(r),h.setStorageKeySeparator(o)}var c;!function(e){e[e.local=0]="local",e[e.session=1]="session"}(c||(c={}));var u,l="ng2-webstorage",f="|",g=(u={},u[c.local]="local",u[c.session]="session",u),p=l,v=f,h=function(){function e(){}return e.isManagedKey=function(e){return 0===e.indexOf(p+v)},e.retrieveKeysFromStorage=function(e){return Object.keys(e).filter(function(e){return 0===e.indexOf(p)})},e.genKey=function(e){if("string"!=typeof e)throw Error("attempt to generate a storage key with a non string value");return""+p+v+e.toString().toLowerCase()},e.setStorageKeyPrefix=function(e){void 0===e&&(e=l),p=e},e.setStorageKeySeparator=function(e){void 0===e&&(e=f),v=e},e}(),d=function(){function e(){}return e.observe=function(e,r){var o=this.genObserverKey(e,r);return o in this.observers?this.observers[o]:this.observers[o]=new t.EventEmitter},e.emit=function(e,t,r){var o=this.genObserverKey(e,t);o in this.observers&&this.observers[o].emit(r)},e.genObserverKey=function(e,t){return e+"|"+t},e.observers={},e}(),y=function(){function e(){}return e.isSecuredField=function(t){return!!~e.securedFields.indexOf(t)},e.getStorage=function(t){return this.mockStorages[t]||(this.mockStorages[t]=e.generateStorage()),this.mockStorages[t]},e.generateStorage=function(){var t={};return Object.defineProperties(t,{setItem:{writable:!1,enumerable:!1,configurable:!1,value:function(t,r){e.isSecuredField(t)||(this[t]=r)}},getItem:{writable:!1,enumerable:!1,configurable:!1,value:function(t){return e.isSecuredField(t)?null:this[t]||null}},removeItem:{writable:!1,enumerable:!1,configurable:!1,value:function(t){e.isSecuredField(t)||delete this[t]}},length:{enumerable:!1,configurable:!1,get:function(){return Object.keys(this).length}}}),t},e.securedFields=["setItem","getItem","removeItem","length"],e.mockStorages={},e}(),S=function(){function e(){}return e.store=function(e,t,r){this.getStorage(e).setItem(t,JSON.stringify(r)),this.cached[e][t]=r,d.emit(e,t,r)},e.retrieve=function(t,r){return this.cached[t][r]?this.cached[t][r]:this.cached[t][r]=e.retrieveFromStorage(t,r)},e.retrieveFromStorage=function(e,t){var r=null;try{r=JSON.parse(this.getStorage(e).getItem(t))}catch(e){console.warn("invalid value for "+t)}return r},e.refresh=function(t,r){if(h.isManagedKey(r)){var o=e.retrieveFromStorage(t,r);null!=o&&o!==this.cached[t][r]&&(this.cached[t][r]=o,d.emit(t,r,o))}},e.clearAll=function(e){var t=this,r=this.getStorage(e);h.retrieveKeysFromStorage(r).forEach(function(o){r.removeItem(o),delete t.cached[e][o],d.emit(e,o,null)})},e.clear=function(e,t){this.getStorage(e).removeItem(t),delete this.cached[e][t],d.emit(e,t,null)},e.getStorage=function(e){return this.isStorageAvailable(e)?this.getWStorage(e):y.getStorage(e)},e.getWStorage=function(e){var t;switch(e){case c.local:t=localStorage;break;case c.session:t=sessionStorage;break;default:throw Error("invalid storage type")}return t},e.isStorageAvailable=function(e){if("boolean"==typeof this.storageAvailability[e])return this.storageAvailability[e];var t=!0,r=this.getWStorage(e);if("object"==typeof r)try{r.setItem("test-storage","foobar"),r.removeItem("test-storage")}catch(e){t=!1}else t=!1;return t||console.warn(g[e]+" storage unavailable, Ng2Webstorage will use a fallback strategy instead"),this.storageAvailability[e]=t},e.cached=(t={},t[c.local]={},t[c.session]={},t),e.storageAvailability=(r={},r[c.local]=null,r[c.session]=null,r),e;var t,r}(),b=function(){function e(e){void 0===e&&(e=null),this.sType=e,this.sType=e}return e.prototype.store=function(e,t){var r=h.genKey(e);S.store(this.sType,r,t)},e.prototype.retrieve=function(e){var t=h.genKey(e);return S.retrieve(this.sType,t)},e.prototype.clear=function(e){e?S.clear(this.sType,h.genKey(e)):S.clearAll(this.sType)},e.prototype.observe=function(e){var t=h.genKey(e);return d.observe(this.sType,t)},e}(),m=function(e,t){function r(){this.constructor=e}for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o]);e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)},w=function(e){function r(){e.call(this,c.local)}return m(r,e),r.decorators=[{type:t.Injectable}],r.ctorParameters=function(){return[]},r}(b),O=function(e,t){function r(){this.constructor=e}for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o]);e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)},K=function(e){function r(){e.call(this,c.session)}return O(r,e),r.decorators=[{type:t.Injectable}],r.ctorParameters=function(){return[]},r}(b),I=function(){function e(e){this.prefix=l,this.separator=f,e&&void 0!==e.prefix&&(this.prefix=e.prefix),e&&void 0!==e.separator&&(this.separator=e.separator)}return e}(),x=new t.OpaqueToken("WEBSTORAGE_CONFIG"),F=function(){function e(e,t){this.ngZone=e,t&&(h.setStorageKeyPrefix(t.prefix),h.setStorageKeySeparator(t.separator)),this.initStorageListener()}return e.forRoot=function(t){return{ngModule:e,providers:[{provide:x,useValue:t},{provide:I,useFactory:s,deps:[x]}]}},e.prototype.initStorageListener=function(){var e=this;window&&window.addEventListener("storage",function(t){return e.ngZone.run(function(){var e=window.sessionStorage===t.storageArea?c.session:c.local;S.refresh(e,t.key)})})},e.decorators=[{type:t.NgModule,args:[{declarations:[],providers:[K,w],imports:[]}]}],e.ctorParameters=function(){return[{type:t.NgZone},{type:I,decorators:[{type:t.Optional},{type:t.Inject,args:[I]}]}]},e}();e.WEBSTORAGE_CONFIG=x,e.Ng2Webstorage=F,e.provideConfig=s,e.configure=a,e.WebstorageConfig=I,e.LocalStorage=n,e.SessionStorage=i,e.WebStorage=r,e.WebStorageDecorator=o,e.WebStorageService=b,e.LocalStorageService=w,e.SessionStorageService=K,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -0,1 +1,37 @@ | ||
<a name="1.5.0">v1.5.0</a> | ||
### Deprecation | ||
* **AoT compilation:** Fixed forRoot method to be compliant with AoT compilations | ||
- Example: | ||
* Before: | ||
```typescript | ||
import {Ng2Webstorage, configure as WebstorageConfigure} from 'ng2-webstorage'; | ||
WebstorageConfigure({ | ||
separator: '.', | ||
prefix: 'custom' | ||
}); | ||
@NgModule({ | ||
imports: [Ng2Webstorage], | ||
}) | ||
export class AppModule {} | ||
``` | ||
* After: | ||
```typescript | ||
import {Ng2Webstorage} from 'ng2-webstorage'; | ||
@NgModule({ | ||
imports: [ | ||
Ng2Webstorage.forRoot({ | ||
separator: '.', | ||
prefix: 'custom' | ||
}) | ||
], | ||
}) | ||
export class AppModule {} | ||
``` | ||
<a name="1.4.3">v1.4.3</a> | ||
@@ -23,3 +59,3 @@ | ||
```typescript | ||
import {Ng2Webstorage, configure:WebstorageConfigure} from 'ng2-webstorage'; | ||
import {Ng2Webstorage, configure as WebstorageConfigure} from 'ng2-webstorage'; | ||
@@ -47,3 +83,3 @@ WebstorageConfigure({ | ||
* **source map:** temporarily remove source map from umd version [source-map-loader issue](for webpack/source-map-loader#21) | ||
* **source map:** temporarily remove source map from umd version [source-map-loader issue](https://github.com/webpack/source-map-loader/pull/21) | ||
@@ -50,0 +86,0 @@ |
@@ -1,12 +0,14 @@ | ||
import { NgZone, ModuleWithProviders } from '@angular/core'; | ||
import { ModuleConfig } from './interfaces/config'; | ||
import { NgZone, ModuleWithProviders, OpaqueToken } from '@angular/core'; | ||
import { WebstorageConfig, IWebstorageConfig } from './interfaces/config'; | ||
export * from './interfaces/index'; | ||
export * from './decorators/index'; | ||
export * from './services/index'; | ||
export declare const WEBSTORAGE_CONFIG: OpaqueToken; | ||
export declare class Ng2Webstorage { | ||
private ngZone; | ||
static forRoot({prefix, separator}?: ModuleConfig): ModuleWithProviders; | ||
constructor(ngZone: NgZone); | ||
static forRoot(config?: IWebstorageConfig): ModuleWithProviders; | ||
constructor(ngZone: NgZone, config: WebstorageConfig); | ||
private initStorageListener(); | ||
} | ||
export declare function configure({prefix, separator}?: ModuleConfig): void; | ||
export declare function provideConfig(config: IWebstorageConfig): WebstorageConfig; | ||
export declare function configure({prefix, separator}?: IWebstorageConfig): void; |
@@ -1,2 +0,2 @@ | ||
import { NgModule, NgZone } from '@angular/core'; | ||
import { NgModule, NgZone, OpaqueToken, Inject, Optional } from '@angular/core'; | ||
import { LIB_KEY, LIB_KEY_SEPARATOR } from './constants/lib'; | ||
@@ -6,2 +6,3 @@ import { STORAGE } from './enums/storage'; | ||
import { WebStorageHelper } from './helpers/webStorage'; | ||
import { WebstorageConfig } from './interfaces/config'; | ||
import { KeyStorageHelper } from './helpers/keyStorage'; | ||
@@ -11,16 +12,33 @@ export * from './interfaces/index'; | ||
export * from './services/index'; | ||
export var WEBSTORAGE_CONFIG = new OpaqueToken('WEBSTORAGE_CONFIG'); | ||
export var Ng2Webstorage = (function () { | ||
function Ng2Webstorage(ngZone) { | ||
function Ng2Webstorage(ngZone, config) { | ||
this.ngZone = ngZone; | ||
if (config) { | ||
KeyStorageHelper.setStorageKeyPrefix(config.prefix); | ||
KeyStorageHelper.setStorageKeySeparator(config.separator); | ||
} | ||
this.initStorageListener(); | ||
} | ||
Ng2Webstorage.forRoot = function (_a) { | ||
var _b = _a === void 0 ? { prefix: LIB_KEY, separator: LIB_KEY_SEPARATOR } : _a, prefix = _b.prefix, separator = _b.separator; | ||
KeyStorageHelper.setStorageKeyPrefix(prefix); | ||
KeyStorageHelper.setStorageKeySeparator(separator); | ||
return { ngModule: Ng2Webstorage, providers: [] }; | ||
Ng2Webstorage.forRoot = function (config) { | ||
return { | ||
ngModule: Ng2Webstorage, | ||
providers: [ | ||
{ | ||
provide: WEBSTORAGE_CONFIG, | ||
useValue: config | ||
}, | ||
{ | ||
provide: WebstorageConfig, | ||
useFactory: provideConfig, | ||
deps: [ | ||
WEBSTORAGE_CONFIG | ||
] | ||
} | ||
] | ||
}; | ||
}; | ||
Ng2Webstorage.prototype.initStorageListener = function () { | ||
var _this = this; | ||
if (window) | ||
if (window) { | ||
window.addEventListener('storage', function (event) { return _this.ngZone.run(function () { | ||
@@ -30,2 +48,3 @@ var storage = window.sessionStorage === event.storageArea ? STORAGE.session : STORAGE.local; | ||
}); }); | ||
} | ||
}; | ||
@@ -42,7 +61,13 @@ Ng2Webstorage.decorators = [ | ||
{ type: NgZone, }, | ||
{ type: WebstorageConfig, decorators: [{ type: Optional }, { type: Inject, args: [WebstorageConfig,] },] }, | ||
]; }; | ||
return Ng2Webstorage; | ||
}()); | ||
export function provideConfig(config) { | ||
return new WebstorageConfig(config); | ||
} | ||
export function configure(_a) { | ||
var _b = _a === void 0 ? { prefix: LIB_KEY, separator: LIB_KEY_SEPARATOR } : _a, prefix = _b.prefix, separator = _b.separator; | ||
/*@Deprecation*/ | ||
console.warn('[ng2-webstorage:deprecation] The configure method is deprecated since the v1.5.0, consider to use forRoot instead'); | ||
KeyStorageHelper.setStorageKeyPrefix(prefix); | ||
@@ -49,0 +74,0 @@ KeyStorageHelper.setStorageKeySeparator(separator); |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"Ng2Webstorage":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[],"providers":[{"__symbolic":"reference","module":"./services/index","name":"SessionStorageService"},{"__symbolic":"reference","module":"./services/index","name":"LocalStorageService"}],"imports":[]}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"NgZone"}]}],"initStorageListener":[{"__symbolic":"method"}]}},"configure":{"__symbolic":"function"}},"exports":[{"from":"./interfaces/index"},{"from":"./decorators/index"},{"from":"./services/index"}]},{"__symbolic":"module","version":1,"metadata":{"Ng2Webstorage":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[],"providers":[{"__symbolic":"reference","module":"./services/index","name":"SessionStorageService"},{"__symbolic":"reference","module":"./services/index","name":"LocalStorageService"}],"imports":[]}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"NgZone"}]}],"initStorageListener":[{"__symbolic":"method"}]}},"configure":{"__symbolic":"function"}},"exports":[{"from":"./interfaces/index"},{"from":"./decorators/index"},{"from":"./services/index"}]}] | ||
[{"__symbolic":"module","version":3,"metadata":{"WEBSTORAGE_CONFIG":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"OpaqueToken"},"arguments":["WEBSTORAGE_CONFIG"]},"Ng2Webstorage":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[],"providers":[{"__symbolic":"reference","module":"./services/index","name":"SessionStorageService"},{"__symbolic":"reference","module":"./services/index","name":"LocalStorageService"}],"imports":[]}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional"}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject"},"arguments":[{"__symbolic":"reference","module":"./interfaces/config","name":"WebstorageConfig"}]}]],"parameters":[{"__symbolic":"reference","module":"@angular/core","name":"NgZone"},{"__symbolic":"reference","module":"./interfaces/config","name":"WebstorageConfig"}]}],"initStorageListener":[{"__symbolic":"method"}]},"statics":{"forRoot":{"__symbolic":"function","parameters":["config"],"value":{"ngModule":{"__symbolic":"reference","name":"Ng2Webstorage"},"providers":[{"provide":{"__symbolic":"reference","name":"WEBSTORAGE_CONFIG"},"useValue":{"__symbolic":"reference","name":"config"}},{"provide":{"__symbolic":"reference","module":"./interfaces/config","name":"WebstorageConfig"},"useFactory":{"__symbolic":"reference","name":"provideConfig"},"deps":[{"__symbolic":"reference","name":"WEBSTORAGE_CONFIG"}]}]}}}},"provideConfig":{"__symbolic":"function","parameters":["config"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"./interfaces/config","name":"WebstorageConfig"},"arguments":[{"__symbolic":"reference","name":"config"}]}},"configure":{"__symbolic":"function"}},"exports":[{"from":"./interfaces/index"},{"from":"./decorators/index"},{"from":"./services/index"}]},{"__symbolic":"module","version":1,"metadata":{"WEBSTORAGE_CONFIG":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"OpaqueToken"},"arguments":["WEBSTORAGE_CONFIG"]},"Ng2Webstorage":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[],"providers":[{"__symbolic":"reference","module":"./services/index","name":"SessionStorageService"},{"__symbolic":"reference","module":"./services/index","name":"LocalStorageService"}],"imports":[]}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional"}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject"},"arguments":[{"__symbolic":"reference","module":"./interfaces/config","name":"WebstorageConfig"}]}]],"parameters":[{"__symbolic":"reference","module":"@angular/core","name":"NgZone"},{"__symbolic":"reference","module":"./interfaces/config","name":"WebstorageConfig"}]}],"initStorageListener":[{"__symbolic":"method"}]},"statics":{"forRoot":{"__symbolic":"function","parameters":["config"],"value":{"ngModule":{"__symbolic":"reference","name":"Ng2Webstorage"},"providers":[{"provide":{"__symbolic":"reference","name":"WEBSTORAGE_CONFIG"},"useValue":{"__symbolic":"reference","name":"config"}},{"provide":{"__symbolic":"reference","module":"./interfaces/config","name":"WebstorageConfig"},"useFactory":{"__symbolic":"reference","name":"provideConfig"},"deps":[{"__symbolic":"reference","name":"WEBSTORAGE_CONFIG"}]}]}}}},"provideConfig":{"__symbolic":"function","parameters":["config"],"value":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"./interfaces/config","name":"WebstorageConfig"},"arguments":[{"__symbolic":"reference","name":"config"}]}},"configure":{"__symbolic":"function"}},"exports":[{"from":"./interfaces/index"},{"from":"./decorators/index"},{"from":"./services/index"}]}] |
@@ -1,1 +0,1 @@ | ||
export declare const LocalStorage: (webstorageKey?: string) => (targetedClass: Object, raw: string) => void; | ||
export declare function LocalStorage(webSKey?: string): (targetedClass: Object, raw: string) => void; |
@@ -1,6 +0,9 @@ | ||
import { WebStorage } from './webStorage'; | ||
import { WebStorageDecorator } from './webStorage'; | ||
import { STORAGE } from '../enums/storage'; | ||
export var LocalStorage = function LocalStorageDecorator(webstorageKey) { | ||
return WebStorage(webstorageKey, STORAGE.local); | ||
}; | ||
export function LocalStorage(webSKey) { | ||
return function (targetedClass, raw) { | ||
WebStorageDecorator(webSKey, STORAGE.local, targetedClass, raw); | ||
}; | ||
} | ||
; | ||
//# sourceMappingURL=localStorage.js.map |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"LocalStorage":{"__symbolic":"error","message":"Function call not supported","line":3,"character":28}}},{"__symbolic":"module","version":1,"metadata":{"LocalStorage":{"__symbolic":"error","message":"Function call not supported","line":3,"character":28}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"LocalStorage":{"__symbolic":"function","parameters":["webSKey"],"value":{"__symbolic":"error","message":"Function call not supported","line":4,"character":8}}}},{"__symbolic":"module","version":1,"metadata":{"LocalStorage":{"__symbolic":"function","parameters":["webSKey"],"value":{"__symbolic":"error","message":"Function call not supported","line":4,"character":8}}}}] |
@@ -1,1 +0,1 @@ | ||
export declare const SessionStorage: (webstorageKey?: string) => (targetedClass: Object, raw: string) => void; | ||
export declare function SessionStorage(webSKey?: string): (targetedClass: Object, raw: string) => void; |
@@ -1,6 +0,9 @@ | ||
import { WebStorage } from './webStorage'; | ||
import { WebStorageDecorator } from './webStorage'; | ||
import { STORAGE } from '../enums/storage'; | ||
export var SessionStorage = function SessionStorageDecorator(webstorageKey) { | ||
return WebStorage(webstorageKey, STORAGE.session); | ||
}; | ||
export function SessionStorage(webSKey) { | ||
return function (targetedClass, raw) { | ||
WebStorageDecorator(webSKey, STORAGE.session, targetedClass, raw); | ||
}; | ||
} | ||
; | ||
//# sourceMappingURL=sessionStorage.js.map |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"SessionStorage":{"__symbolic":"error","message":"Function call not supported","line":3,"character":30}}},{"__symbolic":"module","version":1,"metadata":{"SessionStorage":{"__symbolic":"error","message":"Function call not supported","line":3,"character":30}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"SessionStorage":{"__symbolic":"function","parameters":["webSKey"],"value":{"__symbolic":"error","message":"Function call not supported","line":4,"character":8}}}},{"__symbolic":"module","version":1,"metadata":{"SessionStorage":{"__symbolic":"function","parameters":["webSKey"],"value":{"__symbolic":"error","message":"Function call not supported","line":4,"character":8}}}}] |
import { STORAGE } from '../enums/storage'; | ||
export declare const WebStorage: (webSKey: string, sType: STORAGE) => (targetedClass: Object, raw: string) => void; | ||
export declare function WebStorage(webSKey: string, sType: STORAGE): (targetedClass: Object, raw: string) => void; | ||
export declare function WebStorageDecorator(webSKey: string, sType: STORAGE, targetedClass: Object, raw: string): void; |
import { KeyStorageHelper, WebStorageHelper } from '../helpers/index'; | ||
export var WebStorage = function WebStorageDecorator(webSKey, sType) { | ||
import { STORAGE } from '../enums/storage'; | ||
export function WebStorage(webSKey, sType) { | ||
return function (targetedClass, raw) { | ||
var key = webSKey || raw; | ||
Object.defineProperty(targetedClass, raw, { | ||
get: function () { | ||
var sKey = KeyStorageHelper.genKey(key); | ||
return WebStorageHelper.retrieve(sType, sKey); | ||
}, | ||
set: function (value) { | ||
var sKey = KeyStorageHelper.genKey(key); | ||
this[sKey] = value; | ||
WebStorageHelper.store(sType, sKey, value); | ||
} | ||
}); | ||
WebStorageDecorator(webSKey, STORAGE.local, targetedClass, raw); | ||
}; | ||
}; | ||
} | ||
; | ||
export function WebStorageDecorator(webSKey, sType, targetedClass, raw) { | ||
var key = webSKey || raw; | ||
Object.defineProperty(targetedClass, raw, { | ||
get: function () { | ||
var sKey = KeyStorageHelper.genKey(key); | ||
return WebStorageHelper.retrieve(sType, sKey); | ||
}, | ||
set: function (value) { | ||
var sKey = KeyStorageHelper.genKey(key); | ||
this[sKey] = value; | ||
WebStorageHelper.store(sType, sKey, value); | ||
} | ||
}); | ||
} | ||
; | ||
//# sourceMappingURL=webStorage.js.map |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"WebStorage":{"__symbolic":"error","message":"Function call not supported","line":3,"character":26}}},{"__symbolic":"module","version":1,"metadata":{"WebStorage":{"__symbolic":"error","message":"Function call not supported","line":3,"character":26}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"WebStorage":{"__symbolic":"function","parameters":["webSKey","sType"],"value":{"__symbolic":"error","message":"Function call not supported","line":4,"character":8}},"WebStorageDecorator":{"__symbolic":"function"}}},{"__symbolic":"module","version":1,"metadata":{"WebStorage":{"__symbolic":"function","parameters":["webSKey","sType"],"value":{"__symbolic":"error","message":"Function call not supported","line":4,"character":8}},"WebStorageDecorator":{"__symbolic":"function"}}}] |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"KeyStorageHelper":{"__symbolic":"class","statics":{"isManagedKey":{"__symbolic":"function","parameters":["sKey"],"value":{"__symbolic":"binop","operator":"===","left":{"__symbolic":"call","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"sKey"},"member":"indexOf"},"arguments":[{"__symbolic":"binop","operator":"+","left":{"__symbolic":"reference","module":"../constants/lib","name":"LIB_KEY"},"right":{"__symbolic":"reference","module":"../constants/lib","name":"LIB_KEY_SEPARATOR"}}]},"right":0}},"retrieveKeysFromStorage":{"__symbolic":"function","parameters":["storage"],"value":{"__symbolic":"error","message":"Function call not supported","line":12,"character":37}}}}}},{"__symbolic":"module","version":1,"metadata":{"KeyStorageHelper":{"__symbolic":"class","statics":{"isManagedKey":{"__symbolic":"function","parameters":["sKey"],"value":{"__symbolic":"binop","operator":"===","left":{"__symbolic":"call","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"sKey"},"member":"indexOf"},"arguments":[{"__symbolic":"binop","operator":"+","left":{"__symbolic":"reference","module":"../constants/lib","name":"LIB_KEY"},"right":{"__symbolic":"reference","module":"../constants/lib","name":"LIB_KEY_SEPARATOR"}}]},"right":0}},"retrieveKeysFromStorage":{"__symbolic":"function","parameters":["storage"],"value":{"__symbolic":"error","message":"Function call not supported","line":12,"character":37}}}}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"KeyStorageHelper":{"__symbolic":"class","statics":{"isManagedKey":{"__symbolic":"function","parameters":["sKey"],"value":{"__symbolic":"binop","operator":"===","left":{"__symbolic":"call","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"sKey"},"member":"indexOf"},"arguments":[{"__symbolic":"binop","operator":"+","left":{"__symbolic":"reference","module":"../constants/lib","name":"LIB_KEY"},"right":{"__symbolic":"reference","module":"../constants/lib","name":"LIB_KEY_SEPARATOR"}}]},"right":0}},"retrieveKeysFromStorage":{"__symbolic":"function","parameters":["storage"],"value":{"__symbolic":"error","message":"Function call not supported","line":13,"character":37}}}}}},{"__symbolic":"module","version":1,"metadata":{"KeyStorageHelper":{"__symbolic":"class","statics":{"isManagedKey":{"__symbolic":"function","parameters":["sKey"],"value":{"__symbolic":"binop","operator":"===","left":{"__symbolic":"call","expression":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"sKey"},"member":"indexOf"},"arguments":[{"__symbolic":"binop","operator":"+","left":{"__symbolic":"reference","module":"../constants/lib","name":"LIB_KEY"},"right":{"__symbolic":"reference","module":"../constants/lib","name":"LIB_KEY_SEPARATOR"}}]},"right":0}},"retrieveKeysFromStorage":{"__symbolic":"function","parameters":["storage"],"value":{"__symbolic":"error","message":"Function call not supported","line":13,"character":37}}}}}}] |
@@ -1,4 +0,9 @@ | ||
export interface ModuleConfig { | ||
export interface IWebstorageConfig { | ||
prefix?: string; | ||
separator?: string; | ||
} | ||
export declare class WebstorageConfig implements IWebstorageConfig { | ||
prefix: string; | ||
separator: string; | ||
constructor(config?: IWebstorageConfig); | ||
} |
@@ -0,1 +1,15 @@ | ||
import { LIB_KEY, LIB_KEY_SEPARATOR } from '../constants/lib'; | ||
export var WebstorageConfig = (function () { | ||
function WebstorageConfig(config) { | ||
this.prefix = LIB_KEY; | ||
this.separator = LIB_KEY_SEPARATOR; | ||
if (config && config.prefix !== undefined) { | ||
this.prefix = config.prefix; | ||
} | ||
if (config && config.separator !== undefined) { | ||
this.separator = config.separator; | ||
} | ||
} | ||
return WebstorageConfig; | ||
}()); | ||
//# sourceMappingURL=config.js.map |
export * from './webStorage'; | ||
export * from './storage'; | ||
export * from './config'; |
export * from './webStorage'; | ||
export * from './storage'; | ||
export * from './config'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{},"exports":[{"from":"./webStorage"},{"from":"./storage"}]},{"__symbolic":"module","version":1,"metadata":{},"exports":[{"from":"./webStorage"},{"from":"./storage"}]}] | ||
[{"__symbolic":"module","version":3,"metadata":{},"exports":[{"from":"./webStorage"},{"from":"./storage"},{"from":"./config"}]},{"__symbolic":"module","version":1,"metadata":{},"exports":[{"from":"./webStorage"},{"from":"./storage"},{"from":"./config"}]}] |
{ | ||
"name": "ng2-webstorage", | ||
"version": "1.4.3", | ||
"version": "1.5.0", | ||
"description": "angular2 webstorage manager", | ||
@@ -5,0 +5,0 @@ "main": "bundles/core.umd.js", |
@@ -45,27 +45,3 @@ # ng2-webstorage | ||
``` | ||
Because of the decorators needs, you can't use *for Root* to configure the library with AoT compilations, an exposed function named *configure* is available to handle this case. | ||
```typescript | ||
import {NgModule} from '@angular/core'; | ||
import {BrowserModule} from '@angular/platform-browser'; | ||
import {Ng2Webstorage, configure} from 'ng2-webstorage'; | ||
configure({ prefix: 'custom', separator: '.' }); | ||
// import {Ng2Webstorage, configure: WebstorageConfigure} from 'ng2-webstorage'; // Don't forget you can make an alias if the configure key is already in use | ||
// WebstorageConfigure({ prefix: 'custom', separator: '.' }); | ||
@NgModule({ | ||
declarations: [...], | ||
imports: [ | ||
BrowserModule, | ||
Ng2Webstorage, | ||
], | ||
bootstrap: [...] | ||
}) | ||
export class AppModule { | ||
} | ||
``` | ||
If you're using systemJS, you have to reference the umd version of the lib in your config. | ||
@@ -268,3 +244,3 @@ ```` typescript | ||
###<a name="s_sessionStorage">`SessionStorageService`</a> | ||
###<a name="s_sessionstorage">`SessionStorageService`</a> | ||
> The api is identical as the LocalStorageService's | ||
@@ -271,0 +247,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
214075
86
920
308