import { Inject , Injectable , PLATFORM_ID } from '@angular/core' ; import { MemoryStorage } from '../interfaces/memory-storage.interface' ; import { SessionStorage } from '../interfaces/session-storage.interface' ; import { storageAvailable } from '../utils/storage.util' ; /**
 * Browser session storage
 */ @ Injectable ( ) export class BaseSessionStorage implements SessionStorage { /**
     * Storage
     */ private readonly storage : Storage ; constructor ( private memoryStorage , @ Inject ( PLATFORM_ID ) private platformId ) { if ( storageAvailable ( 'sessionStorage' ) ) { this . storage = window . sessionStorage ; } else { this . storage = this . memoryStorage ; } } get length ( ) : number { return this . storage . length ; } clear ( ) { this . storage . clear ( ) ; } getItem ( key ) { return this . storage . getItem ( key ) ; } key ( index ) { return this . storage . key ( index ) ; } removeItem ( key ) { this . storage . removeItem ( key ) ; } setItem ( key , value ) { this . storage . setItem ( key , value ) ; } }