@@ -19,7 +19,6 @@ const WaveNullTag = "wave:null";
1919const StyleTagName = "style" ;
2020
2121const VDomObjType_Ref = "ref" ;
22- const VDomObjType_Binding = "binding" ;
2322const VDomObjType_Func = "func" ;
2423
2524const dlog = debug ( "wave:vdom" ) ;
@@ -180,36 +179,12 @@ function isArray(v: any): boolean {
180179 return Array . isArray ( v ) ;
181180}
182181
183- function resolveBinding ( binding : VDomBinding , model : TsunamiModel ) : [ any , string [ ] ] {
184- const bindName = binding . bind ;
185- if ( bindName == null || bindName == "" ) {
186- return [ null , [ ] ] ;
187- }
188- // validate that bindName starts with valid atom prefix and has at least one char after the dot
189- const isValidBinding =
190- ( bindName . startsWith ( "$shared." ) && bindName . length > 8 ) ||
191- ( bindName . startsWith ( "$config." ) && bindName . length > 8 ) ||
192- ( bindName . startsWith ( "$data." ) && bindName . length > 6 ) ;
193-
194- if ( ! isValidBinding ) {
195- return [ null , [ ] ] ;
196- }
197-
198- const atom = model . getAtomContainer ( bindName ) ;
199- if ( atom == null ) {
200- return [ null , [ ] ] ;
201- }
202- return [ atom . val , [ bindName ] ] ;
203- }
204-
205182type GenericPropsType = { [ key : string ] : any } ;
206183
207- // returns props, and a set of atom keys used in the props
208- function convertProps ( elem : VDomElem , model : TsunamiModel ) : [ GenericPropsType , Set < string > ] {
184+ function convertProps ( elem : VDomElem , model : TsunamiModel ) : GenericPropsType {
209185 let props : GenericPropsType = { } ;
210- let atomKeys = new Set < string > ( ) ;
211186 if ( elem . props == null ) {
212- return [ props , atomKeys ] ;
187+ return props ;
213188 }
214189 for ( let key in elem . props ) {
215190 let val = elem . props [ key ] ;
@@ -232,32 +207,9 @@ function convertProps(elem: VDomElem, model: TsunamiModel): [GenericPropsType, S
232207 props [ key ] = convertVDomFunc ( model , valFunc , elem . waveid , key ) ;
233208 continue ;
234209 }
235- if ( isObject ( val ) && val . type == VDomObjType_Binding ) {
236- const [ propVal , atomDeps ] = resolveBinding ( val as VDomBinding , model ) ;
237- props [ key ] = propVal ;
238- for ( let atomDep of atomDeps ) {
239- atomKeys . add ( atomDep ) ;
240- }
241- continue ;
242- }
243- if ( key == "style" && isObject ( val ) ) {
244- // assuming the entire style prop wasn't bound, look through the individual keys and bind them
245- for ( let styleKey in val ) {
246- let styleVal = val [ styleKey ] ;
247- if ( isObject ( styleVal ) && styleVal . type == VDomObjType_Binding ) {
248- const [ stylePropVal , styleAtomDeps ] = resolveBinding ( styleVal as VDomBinding , model ) ;
249- val [ styleKey ] = stylePropVal ;
250- for ( let styleAtomDep of styleAtomDeps ) {
251- atomKeys . add ( styleAtomDep ) ;
252- }
253- }
254- }
255- props [ key ] = val ;
256- continue ;
257- }
258210 props [ key ] = val ;
259211 }
260- return [ props , atomKeys ] ;
212+ return props ;
261213}
262214
263215function convertChildren ( elem : VDomElem , model : TsunamiModel ) : React . ReactNode [ ] {
@@ -277,35 +229,9 @@ function convertChildren(elem: VDomElem, model: TsunamiModel): React.ReactNode[]
277229 return childrenComps ;
278230}
279231
280- function stringSetsEqual ( set1 : Set < string > , set2 : Set < string > ) : boolean {
281- if ( set1 . size != set2 . size ) {
282- return false ;
283- }
284- for ( let elem of set1 ) {
285- if ( ! set2 . has ( elem ) ) {
286- return false ;
287- }
288- }
289- return true ;
290- }
291-
292232function useVDom ( model : TsunamiModel , elem : VDomElem ) : GenericPropsType {
293- const version = jotai . useAtomValue ( model . getVDomNodeVersionAtom ( elem ) ) ;
294- const [ oldAtomKeys , setOldAtomKeys ] = React . useState < Set < string > > ( new Set ( ) ) ;
295- let [ props , atomKeys ] = convertProps ( elem , model ) ;
296- React . useEffect ( ( ) => {
297- if ( stringSetsEqual ( atomKeys , oldAtomKeys ) ) {
298- return ;
299- }
300- model . tagUnuseAtoms ( elem . waveid , oldAtomKeys ) ;
301- model . tagUseAtoms ( elem . waveid , atomKeys ) ;
302- setOldAtomKeys ( atomKeys ) ;
303- } , [ atomKeys ] ) ;
304- React . useEffect ( ( ) => {
305- return ( ) => {
306- model . tagUnuseAtoms ( elem . waveid , oldAtomKeys ) ;
307- } ;
308- } , [ ] ) ;
233+ const version = jotai . useAtomValue ( model . getVDomNodeVersionAtom ( elem ) ) ; // this triggers updates when vdom nodes change
234+ let props = convertProps ( elem , model ) ;
309235 return props ;
310236}
311237
0 commit comments