import { Bloc , BlocObserver , Transition } from '@felangel/bloc' ; enum CounterEvent { increment = 'INCREMENT' , decrement = 'DECREMENT' } class MyBlocObserver extends BlocObserver { onEvent ( _ , event ) { console . log ( `added ${ event }` ) ; } onTransition ( _ , transition ) { console . log ( transition ) ; } onError ( _ , error ) { console . log ( `error: ${ error }` ) ; } } class CounterBloc extends Bloc < CounterEvent , number > { constructor ( ) { super ( 0 ) ; } async * mapEventToState ( event ) { switch ( event ) { case CounterEvent . increment : await wait ( 1000 ) ; yield this . state + 1 ; break ; case CounterEvent . decrement : await wait ( 500 ) ; yield this . state - 1 ; break ; } } } ( async function main ( ) { Bloc . observer = new MyBlocObserver ( ) ; const counterBloc = new CounterBloc ( ) ; counterBloc . add ( CounterEvent . increment ) ; counterBloc . add ( CounterEvent . increment ) ; counterBloc . add ( CounterEvent . increment ) ; counterBloc . add ( CounterEvent . decrement ) ; counterBloc . add ( CounterEvent . decrement ) ; counterBloc . add ( CounterEvent . decrement ) ; } ) ( ) ; async function wait ( ms ) { return new Promise < void > ( ( resolve , _ ) => { setTimeout ( ( ) => { resolve ( ) ; } , ms ) ; } ) ; }