Skip to content

Commit 6cc1969

Browse files
committed
add clientimpl pointer to rootelem for easy access
1 parent c33fc7e commit 6cc1969

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

tsunami/app/root_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var buttonId string
5858

5959
func Test1(t *testing.T) {
6060
log.Printf("hello!\n")
61-
root := engine.MakeRoot()
61+
root := engine.MakeRoot(nil)
6262
root.RegisterComponent("Page", Page)
6363
root.RegisterComponent("Button", Button)
6464
root.Render(vdom.H("Page", nil), &engine.RenderOpts{Resync: false})

tsunami/engine/clientimpl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ type ClientImpl struct {
5454
func makeClient() *ClientImpl {
5555
client := &ClientImpl{
5656
Lock: &sync.Mutex{},
57-
Root: MakeRoot(),
5857
DoneCh: make(chan struct{}),
5958
SSEventCh: make(chan ssEvent, 100),
6059
UrlHandlerMux: http.NewServeMux(),
6160
ServerId: uuid.New().String(),
6261
RootElem: vdom.H(DefaultComponentName, nil),
6362
}
63+
client.Root = MakeRoot(client)
6464
return client
6565
}
6666

tsunami/engine/rootelem.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type RootElem struct {
4343
Atoms map[string]genAtom
4444
atomLock sync.Mutex
4545
RefOperations []vdom.VDomRefOperation
46+
Client *ClientImpl
4647
}
4748

4849
func (r *RootElem) AddRenderWork(id string) {
@@ -84,12 +85,13 @@ func (r *RootElem) GetConfigMap() map[string]any {
8485
return result
8586
}
8687

87-
func MakeRoot() *RootElem {
88+
func MakeRoot(client *ClientImpl) *RootElem {
8889
return &RootElem{
8990
Root: nil,
9091
CFuncs: make(map[string]any),
9192
CompMap: make(map[string]*ComponentImpl),
9293
Atoms: make(map[string]genAtom),
94+
Client: client,
9395
}
9496
}
9597

0 commit comments

Comments
 (0)