Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering a component must reconcile against previous DOM state #124

Merged
merged 1 commit into from
Jul 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dom.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func Rerender(c Component) {
if prevRender == nil {
panic("vecty: Rerender invoked on Component that has never been rendered")
}
nextRender, skip := renderComponent(c)
nextRender, skip := renderComponent(c, prevRender)
if skip {
return
}
Expand Down Expand Up @@ -379,7 +379,7 @@ func render(c ComponentOrHTML, prevRender *HTML) (h *HTML, skip bool) {
v.reconcile(prevRender)
return v, false
case Component:
return renderComponent(v)
return renderComponent(v, prevRender)
default:
panic(fmt.Sprintf("vecty: encountered invalid ComponentOrHTML %T", c))
}
Expand All @@ -388,7 +388,7 @@ func render(c ComponentOrHTML, prevRender *HTML) (h *HTML, skip bool) {
// renderComponent handles rendering the given Component into *HTML. If skip ==
// true is returned, the Component's SkipRender method has signaled the
// component does not need to be rendered and h == nil is returned.
func renderComponent(comp Component) (h *HTML, skip bool) {
func renderComponent(comp Component, prevRender *HTML) (h *HTML, skip bool) {
// Now that we know we are rendering the component, restore friendly
// relations between the component and the previous component.
if comp != comp.Context().prevComponent {
Expand Down Expand Up @@ -419,7 +419,7 @@ func renderComponent(comp Component) (h *HTML, skip bool) {
}

// Restore the actual rendered HTML.
nextRender.reconcile(comp.Context().prevRender)
nextRender.reconcile(prevRender)

// Update the context to consider this render.
comp.Context().prevRender = nextRender
Expand All @@ -431,7 +431,7 @@ func renderComponent(comp Component) (h *HTML, skip bool) {
// RenderBody renders the given component as the document body. The given
// Component's Render method must return a "body" element.
func RenderBody(body Component) {
nextRender, skip := renderComponent(body)
nextRender, skip := renderComponent(body, nil)
if skip {
panic("vecty: RenderBody Component.SkipRender returned true")
}
Expand Down
1 change: 1 addition & 0 deletions dom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ func TestHTML_reconcile_std(t *testing.T) {
})

// TODO(pdf): test (*HTML).reconcile child mutations, and value/checked properties
// TODO(pdf): test multi-pass reconcile of persistent component pointer children, ref: https://github.com/gopherjs/vecty/pull/124
}

// TestHTML_reconcile_nil tests that (*HTML).reconcile(nil) works as expected (i.e.
Expand Down