Skip to content

Commit c33fc7e

Browse files
committed
added RootElem to event/effect global contexts
1 parent 1c91358 commit c33fc7e

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

tsunami/engine/globalctx.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ var globalCtxMutex sync.Mutex
2525

2626
type EventContextImpl struct {
2727
Event vdom.VDomEvent
28+
Root *RootElem
2829
}
2930

3031
type EffectContextImpl struct {
3132
WorkElem EffectWorkElem
3233
WorkType string // "run" or "unmount"
34+
Root *RootElem
3335
}
3436

3537
func setGlobalRenderContext(vc *RenderContextImpl) {

tsunami/engine/rootelem.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func (r *RootElem) Event(event vdom.VDomEvent, globalEventHandler func(vdom.VDom
262262
}
263263
}()
264264

265-
eventCtx := &EventContextImpl{Event: event}
265+
eventCtx := &EventContextImpl{Event: event, Root: r}
266266
withGlobalEventCtx(eventCtx, func() any {
267267
if event.GlobalEventType != "" {
268268
if globalEventHandler == nil {
@@ -299,6 +299,7 @@ func (r *RootElem) runEffectUnmount(work *EffectWorkElem, hook *Hook) {
299299
effectCtx := &EffectContextImpl{
300300
WorkElem: *work,
301301
WorkType: "unmount",
302+
Root: r,
302303
}
303304
withGlobalEffectCtx(effectCtx, func() any {
304305
hook.UnmountFn()
@@ -321,6 +322,7 @@ func (r *RootElem) runEffect(work *EffectWorkElem, hook *Hook) {
321322
effectCtx := &EffectContextImpl{
322323
WorkElem: *work,
323324
WorkType: "run",
325+
Root: r,
324326
}
325327
unmountFn := withGlobalEffectCtx(effectCtx, func() func() {
326328
return hook.Fn()

0 commit comments

Comments
 (0)