@@ -26,7 +26,7 @@ export function mountLayoutWithWebSocket(mountElement, endpoint) {
2626
2727 const ws = new WebSocket ( endpoint ) ;
2828
29- function registerUpdateCallback ( update ) {
29+ function saveUpdateHook ( update ) {
3030 ws . onmessage = ( event ) => {
3131 const [ pathPrefix , patch ] = JSON . parse ( event . data ) ;
3232 update ( pathPrefix , patch ) ;
@@ -42,28 +42,33 @@ export function mountLayoutWithWebSocket(mountElement, endpoint) {
4242 ) ;
4343 }
4444
45- return mountLayout ( mountElement , registerUpdateCallback , sendCallback ) ;
45+ return mountLayout ( mountElement , saveUpdateHook , sendCallback ) ;
4646}
4747
48- export function mountLayout (
49- mountElement ,
50- registerUpdateCallback ,
51- sendCallback
52- ) {
53- return reactDOM . render (
54- html `< ${ Layout }
55- registerUpdateCallback =${ registerUpdateCallback }
56- sendCallback=${ sendCallback }
57- /> ` ,
48+ export function mountLayout ( mountElement , saveUpdateHook , sendEvent ) {
49+ const updateHook = { current : null } ;
50+
51+ function setUpdateHook ( hook ) {
52+ updateHook . current = hook ;
53+ }
54+
55+ reactDOM . render (
56+ html `< ${ Layout } setUpdateHook =${ setUpdateHook } sendEvent=${ sendEvent } /> ` ,
5857 mountElement
5958 ) ;
59+
60+ saveUpdateHook ( ( pathPrefix , patch ) => {
61+ if ( updateHook . current ) {
62+ updateHook . current ( pathPrefix , patch ) ;
63+ }
64+ } ) ;
6065}
6166
62- export default function Layout ( { registerUpdateCallback , sendCallback } ) {
67+ export default function Layout ( { setUpdateHook , sendEvent } ) {
6368 const [ model , setModel ] = react . useState ( { } ) ;
6469
6570 react . useEffect ( ( ) => {
66- registerUpdateCallback ( ( pathPrefix , patch ) => {
71+ setUpdateHook ( ( pathPrefix , patch ) => {
6772 setModel (
6873 jsonpatch . applyPatch (
6974 model ,
@@ -79,7 +84,7 @@ export default function Layout({ registerUpdateCallback, sendCallback }) {
7984 } , [ model ] ) ;
8085
8186 if ( model . tagName ) {
82- return html `< ${ Element } sendEvent =${ sendCallback } model=${ model } /> ` ;
87+ return html `< ${ Element } sendEvent =${ sendEvent } model=${ model } /> ` ;
8388 } else {
8489 return html `< div /> ` ;
8590 }
0 commit comments