From a142097ef0060cb7451dd6acedff4813217f8ae7 Mon Sep 17 00:00:00 2001 From: Marc Stammerjohann Date: Sat, 5 Jan 2019 17:49:55 +0100 Subject: [PATCH] chore(): export plugin, plugin module and symbols --- src/lib/symbols.ts | 41 +++++++++++++++++++++++++++++++++++++++++ src/public_api.ts | 4 +++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/lib/symbols.ts b/src/lib/symbols.ts index 2a463ba..d8f00ef 100644 --- a/src/lib/symbols.ts +++ b/src/lib/symbols.ts @@ -1,4 +1,5 @@ import { InjectionToken } from '@angular/core'; +import { Observable, of } from 'rxjs'; export const enum StorageOption { LocalStorage, @@ -66,3 +67,43 @@ export interface StorageEngine { clear(): void; key(val: number): string; } + +export interface AsyncStorageEngine { + length(): Observable; + getItem(key): Observable; + setItem(key, val): void; + removeItem(key): void; + clear(): void; + key(val: number): Observable; +} + +/** + * @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 { + return of(this._storage.length); + } + + public getItem(key): Observable { + 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 { + return of(this._storage.key(val)); + } +} diff --git a/src/public_api.ts b/src/public_api.ts index 5e31b90..2187259 100644 --- a/src/public_api.ts +++ b/src/public_api.ts @@ -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';