Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Commit

Permalink
listener releasing bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nobonobo committed Jun 11, 2020
1 parent 6cf4bd5 commit 2c0515e
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions wecty.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,27 @@ func (e eventMarkup) markup() Applyer {
}

func (e eventMarkup) apply(node js.Wrapper) {
cb := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
return e.fn(args[0])
})
jv := node.JSValue()
listenerReleaseList = append(listenerReleaseList, func() {
jv.Call("removeEventListener", e.name, cb, false)
cb.Release()
})
jv.Call("addEventListener", e.name, cb, false)
if n, ok := node.(*Node); ok {
cb := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
return e.fn(args[0])
})
jv := node.JSValue()
n.ref().listeners = append(n.ref().listeners, func() {
jv.Call("removeEventListener", e.name, cb, false)
cb.Release()
})
jv.Call("addEventListener", e.name, cb, false)
}
}

// Core ...
type Core struct {
last js.Value
isNode bool
children []Component
mount []bool
update bool
last js.Value
isNode bool
children []Component
mount []bool
listeners []func()
update bool
}

// JSValue ...
Expand Down Expand Up @@ -267,14 +270,9 @@ func cleanup(c Component) {
cleanup(child)
}
core.children = nil
}

func cleanupAll(c Component) {
cleanup(c)
for _, v := range listenerReleaseList {
go v()
for _, v := range core.listeners {
v()
}
listenerReleaseList = nil
}

func finalize() {
Expand Down Expand Up @@ -341,7 +339,7 @@ func Rerender(c Component) {
if target.IsNull() || target.IsUndefined() {
panic("rerender not renderd node")
}
cleanupAll(c)
cleanup(c)
act := document.Get("activeElement").Get("id").String()
newNode := Render(c).html()
replaceNode(newNode, target)
Expand Down

0 comments on commit 2c0515e

Please sign in to comment.