Skip to content

Commit

Permalink
node manager dismount html element
Browse files Browse the repository at this point in the history
  • Loading branch information
maxence-charriere committed Oct 3, 2023
1 parent 06a0fd4 commit c063b65
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/app/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,21 @@ func (m *nodeManager) Dismount(v UI) {
}

func (m *nodeManager) dismountHTML(v HTML) {
panic("not implemented")
for _, child := range v.body() {
m.Dismount(child)
}

for _, handler := range v.events() {
m.dismountHTMLEventHandler(handler)
}

v.setJSElement(nil)
}

func (m *nodeManager) dismountHTMLEventHandler(handler eventHandler) {
if handler.close != nil {
handler.close()
}
}

func (m *nodeManager) dismountComponent(v Composer) error {
Expand Down
36 changes: 36 additions & 0 deletions pkg/app/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,42 @@ func BenchmarkNodeManagerMount(b *testing.B) {
}
}

func TestNodeManagerDismount(t *testing.T) {
t.Run("html element is dismounted", func(t *testing.T) {
var m nodeManager

div, err := m.Mount(1, Div())
require.NoError(t, err)

m.Dismount(div)
require.False(t, div.Mounted())
require.Nil(t, div.JSValue())
})

t.Run("html element child is dismounted", func(t *testing.T) {
var m nodeManager

div, err := m.Mount(1, Div().Body(
Span(),
))
require.NoError(t, err)
span := div.(HTML).body()[0]

m.Dismount(div)
require.False(t, span.Mounted())
})

t.Run("html element event handler is dismounted", func(t *testing.T) {
var m nodeManager

div, err := m.Mount(1, Div().
On("", func(ctx Context, e Event) {}))
require.NoError(t, err)

m.Dismount(div)
})
}

func TestNodeManagerCanUpdate(t *testing.T) {
t.Run("elements with same type can be updated", func(t *testing.T) {
var m nodeManager
Expand Down

0 comments on commit c063b65

Please sign in to comment.