Skip to content

Commit

Permalink
chore(): export plugin, plugin module and symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
marcjulian committed Jan 5, 2019
1 parent 83777cf commit a142097
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/lib/symbols.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { InjectionToken } from '@angular/core';
import { Observable, of } from 'rxjs';

export const enum StorageOption {
LocalStorage,
Expand Down Expand Up @@ -66,3 +67,43 @@ export interface StorageEngine {
clear(): void;
key(val: number): string;
}

export interface AsyncStorageEngine {
length(): Observable<number>;
getItem(key): Observable<any>;
setItem(key, val): void;
removeItem(key): void;
clear(): void;
key(val: number): Observable<string>;
}

/**
* @Description Proxy used around synchronous storage engines to provide the same internal API than async engines
*/
export class AsyncStorageEngineProxy implements AsyncStorageEngine {
constructor(private _storage: StorageEngine) { }

public length(): Observable<number> {
return of(this._storage.length);
}

public getItem<T = any>(key): Observable<T> {
return of(this._storage.getItem(key));
}

public setItem(key, val): void {
this._storage.setItem(key, val);
}

public removeItem(key): void {
this._storage.removeItem(key);
}

public clear(): void {
this._storage.clear();
}

public key(val: number): Observable<string> {
return of(this._storage.key(val));
}
}
4 changes: 3 additions & 1 deletion src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
* Public API Surface of async-storage-plugin
*/

export * from './lib/async-storage.module';
export { NgxsAsyncStoragePluginModule } from './lib/async-storage.module';
export { NgxsAsyncStoragePlugin } from './lib/async-storage.plugin';
export * from './lib/symbols';

0 comments on commit a142097

Please sign in to comment.