From 73d7ad75ccc29b82d84a09544abc8639d963b679 Mon Sep 17 00:00:00 2001 From: Stephen Date: Sun, 4 Oct 2026 18:11:55 -0700 Subject: [PATCH] debugging e2e issue --- package.json | 2 +- src/main/index.tsx | 9 ++- src/main/universe/index.tsx | 146 +++++++++++++++++++++++++----------- 3 files changed, 110 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index 242986b..aecf07e 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,7 @@ "test:watch": "eslint --fix && jest --updateSnapshot --watchAll" }, "types": "dist/index.d.ts", - "version": "1.1.0-alpha.13", + "version": "1.1.0-alpha.14", "dependencies": { "@webkrafters/eagleeye": "^1.0.8", "js-sha512": "^0.9.0", diff --git a/src/main/index.tsx b/src/main/index.tsx index 52a35d2..91e24c3 100644 --- a/src/main/index.tsx +++ b/src/main/index.tsx @@ -107,13 +107,20 @@ export class ObservableContext extends AbstractObservable { return ( selectorMap? : S ) => { const [ channel ] = useState(() => stream( selectorMap )); const [ store, setStore ] = useState(() => makeStore( channel )); + const mounted = useRef( false ); useEffect(() => { channel.selectorMap = selectorMap; }, [ selectorMap ]); useEffect(() => { + // istanbul ignore next + if( mounted.current ) { + setStore( makeStore( channel ) ); + } else { + mounted.current = true; + } channel.addListener( 'data-changed', - () => setStore( makeStore( channel ) ) + () => setStore({ ...store, data: channel.data }) ); return () => channel.endStream(); }, [ channel ]); diff --git a/src/main/universe/index.tsx b/src/main/universe/index.tsx index e651fa2..4bd179d 100644 --- a/src/main/universe/index.tsx +++ b/src/main/universe/index.tsx @@ -239,14 +239,14 @@ export class ObservableUniverse { private _context : Context; private _pCache = null as unknown as ReturnType["defineProvider"]>; - private _obs = null as unknown as ObsResource>; + private _obs = null as unknown as ObsResource>; private _sCache = null as unknown as ReturnType["defineStreamHook"]>; private _util = null as Utility; constructor() { this._context = _createContext( '0:0' ); this._pCache = this.defineProvider(); - this._obs = new ObsResource>(); + this._obs = new ObsResource>(); this._sCache = this.defineStreamHook(); this._util = new Utility( this ); } @@ -400,19 +400,98 @@ export class ObservableUniverse { streamHandle.inc(); return streamHandle; }, [ sMapHash, targetId ]); - - const [ store, setStore ] = useState(() => _makeStore( handle.resource )); + const mounted = useRef( false ); + const [ store, setStore ] = useState(() => makeStore( handle.resource )); useEffect(() => { - const fn = () => setStore( _makeStore( handle.resource ) ); - handle.resource.addListener( 'data-changed', fn ); + const channel = handle.resource; + // istanbul ignore next + if( mounted.current ) { + setStore( makeStore( channel ) ); + } else { + mounted.current = true; + } + const fn = () => setStore({ ...store, data: channel.data }); + channel.addListener( 'data-changed', fn ); return () => { - handle.resource.removeListener( 'data-changed', fn ); + channel.removeListener( 'data-changed', fn ); handle.dec(); } }, [ handle.resource ]); return store as Store; }; } + + // private defineStreamHook() { + // return ( selectorMap? : S ) => { + // const [ sMapHash, updateSMapHash ] = useState(() => this._util.hashSelectorMap( selectorMap )); + // useEffect(() => updateSMapHash( this._util.hashSelectorMap( selectorMap ) ), [ selectorMap ]); + // const targetId = use( this._context ); + // const currChannel = useRef( null as unknown as Channel ); + // const currHandle = useRef( null as unknown as StreamerHandle> ); + // const currUpdater = useRef( null as unknown as () => void ); + // const handle = useMemo(() => { + // const ctxHandle = this._obs.createHandleFor( targetId ); + // let streamHandle = ctxHandle.getChannelHandleAt( sMapHash ); + // if( !streamHandle.isValid ) { + // ctxHandle.addChannelAt( + // sMapHash, ctxHandle.resource.stream( selectorMap ) + // ); + // streamHandle = ctxHandle.getChannelHandleAt( sMapHash ); + // } + // streamHandle.inc(); + // return streamHandle as StreamerHandle>; + // }, [ sMapHash, targetId ]); + + // let [ store, setStore ] = useState>(); + + // if( handle.resource !== currChannel.current ) { + // if( !!currChannel.current ) { + // currChannel.current.removeListener( + // 'data-changed', currUpdater.current + // ); + // currHandle.current.dec(); + // } + // store = makeStore( handle.resource ); + // currChannel.current = handle.resource; + // currHandle.current = handle; + // currUpdater.current = () => { + // // try { + // setStore({ ...store, data: currChannel.current.data }); + // // } catch( e ) { + // // /* istanbul ignore next */ + // // if( !( e as Error ).message.includes( + // // "Cannot read properties of null (reading 'getState')" + // // ) ) { throw e } + // // // allow system gc to clean up scheduled freed streams + // // } + // } + // } + + // // useEffect(() => { + // // setStore( makeStore( handle.resource ) ); + // // return handle.dec.bind( handle ); + // // }, [ handle.resource ] ) + // // useEffect(() => { + // // const fn = () => { + // // try { + // // setStore( makeStore( handle.resource ) ); + // // } catch( e ) { + // // /* istanbul ignore next */ + // // if( !( e as Error ).message.includes( + // // "Cannot read properties of null (reading 'getState')" + // // ) ) { throw e } + // // // allow system gc to clean up scheduled freed streams + // // } + // // } + // // handle.resource.addListener( 'data-changed', fn ); + // // return () => { + // // handle.resource.removeListener( 'data-changed', fn ); + // // } + // // }, [ handle.resource ]); + + // return store as Store; + // }; + // } } export class Utility { @@ -456,7 +535,7 @@ export class Utility { export function createContext() { return new ObservableUniverse() } -function _makeStore< +{/* function _makeStore< T extends State, S extends SelectorMap >( channel : Channel ) { @@ -464,41 +543,18 @@ function _makeStore< s.resetState = intercept( s.resetState ); s.setState = intercept( s.setState ); return s; -} - -function intercept( m : IStore["resetState"] ); -function intercept( m : IStore["setState"] ); -function intercept( m : any ) { - return ( ...args : Parameters ) => { - try { m( ...args ) } catch( e ) { - /* istanbul ignore next */ - if( !e.message.startsWith( "Cannot read properties of null (reading 'getState')" ) ) { - throw e; - } - // allow system gc to clean up scheduled freed streams - } - } -} - -{/* class ErrorBoundary extends Component { - state = { hasError: false, error: null }; - static getDerivedStateFromError(error) { - return { hasError: true, error }; - } - private pushError() { - if( this.state.hasError ) { - console?.warn?. - } - } - componentDidMount(): void { - - } - render() { - if( this.state.hasError ) { - return

Caught by Boundary: { - this.state.error.message - }

; - } - return this.props.children; - } } */} + +// function intercept( m : IStore["resetState"] ); +// function intercept( m : IStore["setState"] ); +// function intercept( m : any ) { +// return ( ...args : Parameters ) => { +// try { m( ...args ) } catch( e ) { +// /* istanbul ignore next */ +// if( !e.message.startsWith( "Cannot read properties of null (reading 'getState')" ) ) { +// throw e; +// } +// // allow system gc to clean up scheduled freed streams +// } +// } +// }