import { defaultState , pureTransitions , TodoActions , TodoState } from '../state_containers/todomvc' ; import { BaseState , BaseStateContainer , createStateContainer } from '../../common/state_containers' ; import { createOsdUrlStateStorage , syncState , INullableBaseStateContainer , } from '../../public/state_sync' ; const tick = ( ) => new Promise ( ( resolve ) => setTimeout ( resolve ) ) ; const stateContainer = createStateContainer < TodoState , TodoActions > ( defaultState , pureTransitions ) ; const { start , stop } = syncState ( { stateContainer : withDefaultState ( stateContainer , defaultState ) , storageKey : '_s' , stateStorage : createOsdUrlStateStorage ( ) , } ) ; start ( ) ; export const result = Promise . resolve ( ) . then ( ( ) => { stateContainer . transitions . add ( { id : 2 , text : 'test' , completed : false , } ) ; return tick ( ) ; } ) . then ( ( ) => { stop ( ) ; return window . location . href ; } ) ; function withDefaultState < State extends BaseState > ( stateContainer , defaultState ) { return { ... stateContainer , set : ( state ) => { stateContainer . set ( state || defaultState ) ; } , } ; }