import { Store , createStore , Reducer , Action , StoreEnhancer , Unsubscribe , Observer , ExtendState } from '../..' ; import 'symbol-observable' ; type BrandedString = string & { _brand : 'type' ; } ; const brandedString = 'a string' as BrandedString ; type State = { a : 'a' ; b : { c : 'c' ; d : 'd' ; } ; e : BrandedString ; } ; const noExtend = { a : 'a' , b : { c : 'c' , d : 'd' } , e : brandedString } ; const noExtendError = { a : 'a' , b : { c : 'c' , d : 'd' } , e : brandedString , f : 'oops' } ; const yesExtend = { a : 'a' , b : { c : 'c' , d : 'd' } , e : brandedString , yes : 'we can' } ; const yesExtendError = { a : 'a' , b : { c : 'c' , d : 'd' } , e : brandedString } ; interface DerivedAction extends Action { type : 'a' ; b : 'b' ; } const reducer = ( state = { a : 'a' , b : { c : 'c' , d : 'd' } , e : brandedString } , action ) : State => { return state ; } ; const reducerWithAction = ( state = { a : 'a' , b : { c : 'c' , d : 'd' } , e : brandedString } , action ) : State => { return state ; } ; const funcWithStore = ( store ) => { } ; const store = createStore ( reducer ) ; const arrayReducer = ( state = [ ] ) => state || [ ] ; const storeWithArrayState = createStore ( arrayReducer ) ; const storeWithPreloadedState = createStore ( reducer , { a : 'a' , b : { c : 'c' , d : 'd' } , e : brandedString } ) ; const storeWithBadPreloadedState = createStore ( reducer , { b : { c : 'c' } , e : brandedString } ) ; const storeWithActionReducer = createStore ( reducerWithAction ) ; const storeWithActionReducerAndPreloadedState = createStore ( reducerWithAction , { a : 'a' , b : { c : 'c' , d : 'd' } , e : brandedString } ) ; funcWithStore ( storeWithActionReducer ) ; funcWithStore ( storeWithActionReducerAndPreloadedState ) ; const storeWithActionReducerAndBadPreloadedState = createStore ( reducerWithAction , { b : { c : 'c' } , e : brandedString } ) ; const enhancer = next => next ; const storeWithSpecificEnhancer = createStore ( reducer , enhancer ) ; const storeWithPreloadedStateAndEnhancer = createStore ( reducer , { a : 'a' , b : { c : 'c' , d : 'd' } , e : brandedString } , enhancer ) ; const storeWithBadPreloadedStateAndEnhancer = createStore ( reducer , { b : { c : 'c' } } , enhancer ) ; store . dispatch ( { type : 'ADD_TODO' , text : 'test' } ) ; const state = store . getState ( ) ; const unsubscribe = store . subscribe ( ( ) => { console . log ( 'Current state:' , store . getState ( ) ) ; } ) ; unsubscribe ( ) ; const newReducer = reducer ; store . replaceReducer ( newReducer ) ; let observable = store [ Symbol . observable ] ( ) ; observable = observable [ Symbol . observable ] ( ) ; const observer = { next ( state ) { console . log ( 'current state:' , state ) ; } } ; const unsubscribeFromObservable = observable . subscribe ( observer ) . unsubscribe ; unsubscribeFromObservable ( ) ;