Skip to content

Commit

Permalink
nodes: Fix updates when number of controls changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
roblillack committed May 26, 2024
1 parent 940370b commit 764203b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (n Node) mount(parent Control) {
}
}

func (n Node) updateChild(idx int, new Control) {
func (n *Node) updateChild(idx int, new Control) {
old := n.Children[idx].Content
if old == nil && new == nil {
return
Expand Down Expand Up @@ -48,7 +48,7 @@ func (n Node) updateChild(idx int, new Control) {
}
}

func (n Node) Update(other Node, parent Control) {
func (n *Node) Update(other Node, parent Control) {
if n.Content != nil && other.Content == nil {
if unmountable, ok := n.Content.(Unmountable); ok {
unmountable.Unmount()
Expand Down
13 changes: 6 additions & 7 deletions rendercontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ func (ctx *RenderContext) Make(render func(*RenderContext) Component) Node {
return root
}

func printNodes(node Node, indent int) {
func printNodes(node *Node, indent int) {
if len(node.Children) == 0 {
fmt.Printf("%s<%T/>\n", strings.Repeat(" ", indent), node.Content)
return
}

fmt.Printf("%s<%T>\n", strings.Repeat(" ", indent), node.Content)
for _, child := range node.Children {
printNodes(child, indent+1)
printNodes(&child, indent+1)
}
fmt.Printf("%s</%T>\n", strings.Repeat(" ", indent), node.Content)
}
Expand Down Expand Up @@ -96,16 +96,15 @@ func (ctx *RenderContext) TriggerUpdate() {

// fmt.Printf("[%v] RENDER TRIGGERED!\n", ctx)
ctx.count = 0
oldTree := ctx.root
// fmt.Println("**** RENDER STARTING ****")
newTree := ctx.BuildNode(ctx.content)
// fmt.Println("**** RENDER DONE ****")

// fmt.Printf("[%v] Old tree: %+v\n", ctx, oldTree)
// printNodes(oldTree, 0)
// fmt.Printf("[%v] Old tree: %+v\n", ctx, ctx.root)
// printNodes(&ctx.root, 0)
// fmt.Printf("[%v] New tree: %+v\n", ctx, newTree)
// printNodes(newTree, 0)
// printNodes(&newTree, 0)

oldTree.Update(newTree, nil)
ctx.root.Update(newTree, nil)
})
}

0 comments on commit 764203b

Please sign in to comment.