import { browser , Storage } from 'webextension-polyfill-ts' ; import { Observable } from 'rxjs' ; export const observeStorage = < T > ( key , defalt ) : Observable < T > => new Observable ( subscriber => { browser . storage . local . get ( key ) . then ( obj => subscriber . next ( key in obj ? obj [ key ] : defalt ) ) ; const listener = ( changes ) : void => { if ( key in changes ) { subscriber . next ( 'newValue' in changes [ key ] ? changes [ key ] . newValue : defalt ) ; } } ; browser . storage . onChanged . addListener ( listener ) ; return ( ) => browser . storage . onChanged . removeListener ( listener ) ; } ) ; export const setStorage = ( key , value ) => browser . storage . local . set ( { [ key ] : value } ) ;