import { injectable } from 'inversify' ; import IStorageOperationModel from './IStorageOperationModel' ; /**
 * StorageOperationModel
 * local storage の set, get, remove を行う
 */ @ injectable ( ) export default class StorageOperationModel implements IStorageOperationModel { private dummySavedValue : any | null = null ; param key param value public set ( key , value ) { try { window . localStorage . setItem ( key , JSON . stringify ( value ) ) ; } catch ( err ) { console . error ( 'local storage save error' ) ; this . dummySavedValue = JSON . parse ( JSON . stringify ( value ) ) ; } } param key return public get ( key ) { let value = null ; try { value = window . localStorage . getItem ( key ) ; } catch ( err ) { return this . dummySavedValue ; } return value === null ? null : JSON . parse ( value ) ; } param key public remove ( key ) { window . localStorage . removeItem ( key ) ; } }