import { FactoryProvider , InjectionToken } from '@angular/core' ; import { LOCAL_STORAGE } from 'ngx-webstorage' ; import { CrossStorageClientI } from './cross-storage-client' ; export class CrossStorageLocalStorageFallback implements CrossStorageClientI { constructor ( protected storage ) { } onConnect ( ) { return Promise . resolve ( ) ; } set ( key , value ) { return this . onConnect ( ) . then ( ( ) => this . storage . setItem ( key , value ) ) ; } get ( key ) { return this . onConnect ( ) . then ( ( ) => this . storage . getItem ( key ) ) ; } clear ( key ? ) { if ( key ) return this . del ( key ) ; return this . onConnect ( ) . then ( ( ) => { this . storage . clear ( ) ; } ) ; } del ( key ? ) { return this . onConnect ( ) . then ( ( ) => this . storage . removeItem ( key ) ) ; } } export const CROSS_STORAGE_LOCAL_STORAGE_FALLBACK = new InjectionToken < CrossStorageClientI > ( 'cross_storage_local_storage_fallback' ) ; export function getCrossStorageLocalStorageFallback ( storage ) { return new CrossStorageLocalStorageFallback ( storage ) ; } export const CrossStorageLocalStorageFallbackProvider = { provide : CROSS_STORAGE_LOCAL_STORAGE_FALLBACK , useFactory : getCrossStorageLocalStorageFallback , deps : [ LOCAL_STORAGE ] } ;