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

diff.diffNode() should return empty array when no changes #412

Open
TimBarham opened this issue Mar 7, 2016 · 0 comments
Open

diff.diffNode() should return empty array when no changes #412

TimBarham opened this issue Mar 7, 2016 · 0 comments

Comments

@TimBarham
Copy link

Hi - I'm using diff.diffNode() and dom.update() directly.

I've noticed if I pass two vNodes with identical structure to diff.diffNode(), I still get back a complicated tree of changes full of updateChildren and updateChild changes (with the final result being a no-op).

I would like to easily detect when diff.diffNode() reports there are no changes. While I can walk the tree and figure it out, it seems more efficient if diff.diffNode() (and `diff.diffChildren()') simply returned an empty array in this scenario.

It seems this can fairly easily be done by something like the following change when returning from diffChildren():

return changes.length ? updateChildren(changes) : [];

And in the isNative case when returning from diffNode():

var changes = diffAttributes(prev, next);
var childDiff = diffChildren(prev, next, path);
if (childDiff.length) {
  changes.push(childDiff);
}

Similar changes would probably be needed for thunks (but I'm not currently using them so I haven't looked at that).

So I'm wondering - is there some philosophical reason not to just return an empty array in these scenarios?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant