import watchDeep from './watchDeep' ; import { ChangeOptions } from './dep' ; export interface IStore { getState ( ) : Record < string , any > ; getComputed ( ) : Record < string , any > ; init ? ( ) : void ; destroy ? ( ) : void ; } type ReactiveThis = { store : Pick < IStore , Exclude < keyof IStore , 'destroy' > > ; } ; export interface ISetData { ( _ , keyPathList , newV , oldV , options ? ) : void ; } export default function reactive < T extends ReactiveThis = ReactiveThis > ( this , setData , onError ? ) { if ( ! this . store ) { throw new Error ( 'no store.' ) ; } this . store . init && this . store . init ( ) ; const watchKeys = ( data ) => { const stop = watchDeep ( data , setData , { onError , immediate : true , } ) ; return [ stop ] ; } ; const stopWatchList = [ ... watchKeys ( this . store . getState ( ) ) , ... watchKeys ( this . store . getComputed ( ) ) ] ; return stopWatchList ; }