import { signal , wire } from '../src/state/index' ; import type { Signal , Wire } from '../src/state/index' ; import { } from 'zora' ; Object . assign ( globalThis , { S_RUNNING : 4 , S_SKIP_RUN_QUEUE : 2 , S_NEEDS_RUN : 1 , } ) ; const state = signal ( { count : 0 , countPlusOne : wire ( function cPO ( $ ) : number { console . log ( 'Computing countPlusOne' ) ; return state . count ( $ ) + 1 ; } ) , countPlusTwo : wire ( function cPT ( $ ) : number { console . log ( 'Computing countPlusTwo' ) ; return state . countPlusOne ( $ ) + 1 ; } ) , } ) ; const handlerFor = < T > ( name ) : ProxyHandler < Signal < T > > => ( { apply : function ( sig , thisArg , arg ) { if ( arg . length === 0 ) { console . group ( `R: state.${ name }()` ) ; const v = sig ( ) ; console . log ( `-> ${ v }` ) ; console . groupEnd ( ) ; return v ; } if ( arg . length === 1 ) { console . group ( `W: state.${ name }(${ arg [ 0 ] })` ) ; sig ( arg [ 0 ] ) ; console . groupEnd ( ) ; return ; } throw '>1 signal argument' ; } , } ) ; const stateProx = { } as typeof state ; let k ; for ( k in state ) stateProx [ k ] = new Proxy ( state [ k ] , handlerFor ( k ) ) ; const w = wire ( function effect ( $ ) { console . log ( 'Effect: count is' , state . count ( $ ) ) ; } ) ; w ( ) ; stateProx . count ( 1 ) ; stateProx . count ( 2 ) ; stateProx . count ( 3 ) ; stateProx . countPlusTwo ( ) ; console . log ( 'count wires' , [ ... state . count . wires ] . map ( ( x ) => x . name ) ) ; console . log ( 'cPO wires' , [ ... state . countPlusOne . wires ] . map ( ( x ) => x . name ) ) ; console . log ( 'cPO cw.sigRS' , [ ... ( state . countPlusOne . cw as Wire ) . sigRS ] . map ( ( x ) => x . name ) ) ; console . log ( 'cPT wires' , [ ... state . countPlusTwo . wires ] . map ( ( x ) => x . name ) ) ; console . log ( 'cPT cw.sigRS' , [ ... ( state . countPlusTwo . cw as Wire ) . sigRS ] . map ( ( x ) => x . name ) ) ; stateProx . count ( 4 ) ; stateProx . countPlusTwo ( ) ; stateProx . countPlusOne ( ) ; stateProx . countPlusTwo ( ) ;