Skip to content
Permalink
Browse files
Updated the packaging
  • Loading branch information
cedx committed Jun 4, 2020
1 parent 5e8265a commit 53290fc27bb3e266be60d0fcd1721b2c30801872
Showing with 15 additions and 10 deletions.
  1. +3 −0 example/main.ts
  2. +6 −8 package.json
  3. +6 −2 src/web_storage.ts
@@ -35,6 +35,9 @@ export class MyComponent implements OnInit {
console.log(this._storage.getObject("baz")); // {qux: 123}
console.log(this._storage.getObject("baz").qux); // 123

// Iterate the storage.
for (const [key, value] of this._storage) console.log(`${key} => ${value}`);

// Delete from the storage.
this._storage.remove("foo");
console.log(this._storage.has("foo")); // false
@@ -13,6 +13,9 @@
"name": "Cédric Belin",
"url": "https://belin.io"
},
"dependencies": {
"tslib": "^2.0.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.901.7",
"@angular-devkit/build-ng-packagr": "^0.901.7",
@@ -41,7 +44,6 @@
"mocha": "^7.2.0",
"ng-packagr": "^9.1.5",
"rxjs": "^6.5.5",
"tslib": "^2.0.0",
"typescript": "^3.9.3",
"zone.js": "^0.10.3"
},
@@ -57,20 +59,16 @@
},
"keywords": [
"angular",
"esm",
"local",
"ngx",
"observable",
"rxjs",
"browser",
"events",
"html",
"service",
"session",
"storage"
],
"peerDependencies": {
"@angular/common": ">=9.1.0",
"@angular/core": ">=9.1.0",
"rxjs": ">=6.5.0",
"tslib": ">=1.11.0",
"zone.js": ">=0.10.0"
},
"repository": {
@@ -16,7 +16,7 @@ export abstract class WebStorage implements Iterable<[string, string|undefined]>
*/
protected constructor(private readonly _backend: Storage) {
this._subscription = fromEvent<StorageEvent>(window, "storage").subscribe(event => {
if (event.storageArea == this._backend) this._emit(event.key, event.oldValue ?? undefined, event.newValue ?? undefined, event.url);
if (event.storageArea == this._backend) this._emit(event.key, event.oldValue, event.newValue, event.url);
});
}

@@ -173,8 +173,12 @@ export abstract class WebStorage implements Iterable<[string, string|undefined]>

/**
* Emits a new storage event.
* @param key The key changed.
* @param oldValue The original value of the key.
* @param newValue The new value of the key.
* @param url The URL of the document whose key changed.
*/
private _emit(key: string|null, oldValue?: string, newValue?: string, url?: string): void {
private _emit(key: string|null, oldValue?: string|null, newValue?: string|null, url?: string): void {
this._onChange.next(new StorageEvent("change", {
key,
newValue,

0 comments on commit 53290fc

Please sign in to comment.