@@ -11,29 +11,44 @@ import (
1111 "strconv"
1212 "strings"
1313 "sync"
14+ "unicode"
1415
1516 "github.com/google/uuid"
1617 "github.com/wavetermdev/waveterm/tsunami/rpctypes"
1718 "github.com/wavetermdev/waveterm/tsunami/util"
1819 "github.com/wavetermdev/waveterm/tsunami/vdom"
20+ "github.com/wavetermdev/waveterm/tsunami/vdomctx"
1921)
2022
23+ const ChildrenPropKey = "children"
24+
2125type RenderOpts struct {
2226 Resync bool
2327}
2428
29+ type Atom struct {
30+ Val any
31+ Dirty bool
32+ UsedBy map [string ]bool // component waveid -> true
33+ }
34+
35+ type EffectWorkElem struct {
36+ Id string
37+ EffectIndex int
38+ }
39+
2540type RootElem struct {
2641 OuterCtx context.Context
2742 Root * ComponentImpl
2843 RenderTs int64
2944 AppTitle string
3045 CFuncs map [string ]any
3146 CompMap map [string ]* ComponentImpl // component waveid -> component
32- EffectWorkQueue []* vdom. EffectWorkElem
47+ EffectWorkQueue []* EffectWorkElem
3348 NeedsRenderMap map [string ]bool
34- Atoms map [string ]* vdom. Atom
49+ Atoms map [string ]* Atom
3550 atomLock sync.Mutex
36- RefOperations []rpctypes .VDomRefOperation
51+ RefOperations []vdom .VDomRefOperation
3752}
3853
3954func (r * RootElem ) AddRenderWork (id string ) {
@@ -44,7 +59,7 @@ func (r *RootElem) AddRenderWork(id string) {
4459}
4560
4661func (r * RootElem ) AddEffectWork (id string , effectIndex int ) {
47- r .EffectWorkQueue = append (r .EffectWorkQueue , & vdom. EffectWorkElem {Id : id , EffectIndex : effectIndex })
62+ r .EffectWorkQueue = append (r .EffectWorkQueue , & EffectWorkElem {Id : id , EffectIndex : effectIndex })
4863}
4964
5065func (r * RootElem ) GetDataMap () map [string ]any {
@@ -64,7 +79,7 @@ func (r *RootElem) GetDataMap() map[string]any {
6479func (r * RootElem ) GetConfigMap () map [string ]any {
6580 r .atomLock .Lock ()
6681 defer r .atomLock .Unlock ()
67-
82+
6883 result := make (map [string ]any )
6984 for atomName , atom := range r .Atoms {
7085 if strings .HasPrefix (atomName , "$config." ) {
@@ -80,24 +95,23 @@ func MakeRoot() *RootElem {
8095 Root : nil ,
8196 CFuncs : make (map [string ]any ),
8297 CompMap : make (map [string ]* ComponentImpl ),
83- Atoms : make (map [string ]* vdom. Atom ),
98+ Atoms : make (map [string ]* Atom ),
8499 }
85100}
86101
87- func (r * RootElem ) ensureAtomNoLock (name string ) * vdom. Atom {
102+ func (r * RootElem ) ensureAtomNoLock (name string ) * Atom {
88103 atom , ok := r .Atoms [name ]
89104 if ! ok {
90- atom = & vdom. Atom {UsedBy : make (map [string ]bool )}
105+ atom = & Atom {UsedBy : make (map [string ]bool )}
91106 r .Atoms [name ] = atom
92107 }
93108 return atom
94109}
95110
96-
97111func (r * RootElem ) AtomSetUsedBy (atomName string , waveId string , used bool ) {
98112 r .atomLock .Lock ()
99113 defer r .atomLock .Unlock ()
100-
114+
101115 atom := r .ensureAtomNoLock (atomName )
102116 if used {
103117 atom .UsedBy [waveId ] = true
@@ -109,7 +123,7 @@ func (r *RootElem) AtomSetUsedBy(atomName string, waveId string, used bool) {
109123func (r * RootElem ) AtomAddRenderWork (atomName string ) {
110124 r .atomLock .Lock ()
111125 defer r .atomLock .Unlock ()
112-
126+
113127 atom , ok := r .Atoms [atomName ]
114128 if ! ok {
115129 return
@@ -297,7 +311,7 @@ func (r *RootElem) render(elem *vdom.VDomElem, comp **ComponentImpl, opts *Rende
297311 r .renderText (elem .Text , comp )
298312 return
299313 }
300- if vdom . IsBaseTag (elem .Tag ) {
314+ if isBaseTag (elem .Tag ) {
301315 // simple vdom, fragment, wave element
302316 r .renderSimple (elem , comp , opts )
303317 return
@@ -421,9 +435,9 @@ func (r *RootElem) renderComponent(cfunc any, elem *vdom.VDomElem, comp **Compon
421435 for k , v := range elem .Props {
422436 props [k ] = v
423437 }
424- props [vdom . ChildrenPropKey ] = elem .Children
438+ props [ChildrenPropKey ] = elem .Children
425439 vc := MakeContextVal (r , * comp , opts )
426- ctx := vdom .WithRenderContext (r .OuterCtx , vc )
440+ ctx := vdomctx .WithRenderContext (r .OuterCtx , vc )
427441 renderedElem := callCFunc (cfunc , ctx , props )
428442 rtnElemArr := vdom .PartToElems (renderedElem )
429443 if len (rtnElemArr ) == 0 {
@@ -472,11 +486,11 @@ func (r *RootElem) UpdateRef(updateRef rpctypes.VDomRefUpdate) {
472486 r .AddRenderWork (waveId )
473487}
474488
475- func (r * RootElem ) QueueRefOp (op rpctypes .VDomRefOperation ) {
489+ func (r * RootElem ) QueueRefOp (op vdom .VDomRefOperation ) {
476490 r .RefOperations = append (r .RefOperations , op )
477491}
478492
479- func (r * RootElem ) GetRefOperations () []rpctypes .VDomRefOperation {
493+ func (r * RootElem ) GetRefOperations () []vdom .VDomRefOperation {
480494 ops := r .RefOperations
481495 r .RefOperations = nil
482496 return ops
@@ -573,17 +587,16 @@ func VDomFuncCallFn(vdf *vdom.VDomFunc, event vdom.VDomEvent) {
573587 }
574588}
575589
576- func QueueRefOp ( ctx context. Context , ref * vdom. VDomRef , op rpctypes. VDomRefOperation ) {
577- if ref == nil || ! ref . HasCurrent {
578- return
590+ func isBaseTag ( tag string ) bool {
591+ if tag == "" {
592+ return false
579593 }
580- vcIf := vdom .GetRenderContext (ctx )
581- if vcIf == nil {
582- panic ("QueueRefOp must be called within a component (no context)" )
594+ if tag == vdom .TextTag || tag == vdom .WaveTextTag || tag == vdom .WaveNullTag || tag == vdom .FragmentTag {
595+ return true
583596 }
584- vc := vcIf .(* VDomContextVal )
585- if op .RefId == "" {
586- op .RefId = ref .RefId
597+ if tag [0 ] == '#' {
598+ return true
587599 }
588- vc .Root .QueueRefOp (op )
600+ firstChar := rune (tag [0 ])
601+ return unicode .IsLower (firstChar )
589602}
0 commit comments