import { globalState } from '../core/globalState' ; import { Reaction , Options , Scheduler , Runner } from '../typings' ; function isLazy ( options ? ) { return options && options . lazy ; } function getScheduler ( options ? ) { if ( ! options ) return ; return options . scheduler ; } export function observe ( reaction , options ? ) { const scheduler = getScheduler ( options ) ; const { runners } = globalState ; const runner = { reaction , scheduler } ; runners . push ( runner ) ; if ( ! isLazy ( options ) ) reaction ( ) ; return reaction ; }