@@ -2,7 +2,7 @@ import { patch, create } from "omdomdom/lib/omdomdom.es.js"
22import { SocketConnection , Update , Redirect } from './sockets'
33import { listenChange , listenClick , listenDblClick , listenFormSubmit , listenLoad , listenTopLevel , listenInput , listenKeydown , listenKeyup , listenMouseEnter , listenMouseLeave } from './events'
44import { actionMessage , ActionMessage , Request , newRequest } from './action'
5- import { ViewId , Metadata , parseMetadata } from './message'
5+ import { ViewId , Metadata , parseMetadata , ViewState } from './message'
66import { setQuery } from "./browser"
77import { parseResponse , Response , LiveUpdate } from './response'
88
@@ -46,8 +46,10 @@ async function runAction(target: HyperView, action: string, form?: FormData) {
4646 target . classList . add ( "hyp-loading" )
4747 } , 100 )
4848
49+ let state = target . dataset . state
50+
4951 let req = newRequest ( )
50- let msg = actionMessage ( target . id , action , req . requestId , form )
52+ let msg = actionMessage ( target . id , action , state , req . requestId , form )
5153
5254 // Set the requestId
5355 target . activeRequest = req
@@ -110,6 +112,7 @@ function handleUpdate(res: Update): HyperView {
110112 // Patch the node
111113 const old : VNode = create ( target )
112114 let next : VNode = create ( update . content )
115+ let state = ( next . attributes as any ) [ "data-state" ]
113116 next . attributes = old . attributes
114117 patch ( next , old )
115118
@@ -118,21 +121,24 @@ function handleUpdate(res: Update): HyperView {
118121 let newTarget = document . getElementById ( target . id )
119122 dispatchContent ( newTarget )
120123
121- if ( newTarget ) {
122- // execute the metadata, anything that doesn't interrupt the dom update
123- runMetadata ( res . meta , newTarget )
124-
125- // now way for these to bubble)
126- listenLoad ( newTarget )
127- listenMouseEnter ( newTarget )
128- listenMouseLeave ( newTarget )
129- fixInputs ( newTarget )
130- enrichHyperViews ( newTarget )
131- }
132- else {
124+ if ( ! newTarget ) {
133125 console . warn ( "Target Missing: " , target . id )
126+ return target
134127 }
135128
129+ // re-add state attribute
130+ newTarget . dataset . state = state
131+
132+ // execute the metadata, anything that doesn't interrupt the dom update
133+ runMetadata ( res . meta , newTarget )
134+
135+ // now way for these to bubble)
136+ listenLoad ( newTarget )
137+ listenMouseEnter ( newTarget )
138+ listenMouseLeave ( newTarget )
139+ fixInputs ( newTarget )
140+ enrichHyperViews ( newTarget )
141+
136142 return target
137143}
138144// catch (err) {
0 commit comments