module Sfx { export class StorageService extends Observable { public getValueNumber ( key , defaultValue ) { return this . getValueT < number > ( key , ( item ) => Number ( item ) , defaultValue ) ; } public getValueString ( key , defaultValue ) { return this . getValueT < string > ( key , ( item ) => item , defaultValue ) ; } public getValueBoolean ( key , defaultValue ) { return this . getValueT < boolean > ( key , ( item ) => item === "true" , defaultValue ) ; } public getValueT < T > ( key , convert , defaultValue ) { let value = localStorage . getItem ( key ) ; if ( value ) { return convert ( value ) ; } return defaultValue ; } public clear ( key ) { if ( this . isDefined ( key ) ) { localStorage . removeItem ( key ) ; } } public isDefined ( key ) { return ! ! localStorage . getItem ( key ) ; } public setValue ( key , newValue ) { let oldValue = localStorage . getItem ( key ) || "" ; if ( oldValue !== newValue . toString ( ) ) { localStorage . setItem ( key , newValue . toString ( ) ) ; this . notify ( key , oldValue , newValue . toString ( ) ) ; } } } ( function ( ) { let module = angular . module ( "storageService" , [ ] ) ; module . factory ( "storage" , ( ) => new StorageService ( ) ) ; } ) ( ) ; }