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

reorderChildren should remove child from back to front #357

Open
Javey opened this issue Jan 5, 2016 · 0 comments
Open

reorderChildren should remove child from back to front #357

Javey opened this issue Jan 5, 2016 · 0 comments

Comments

@Javey
Copy link

Javey commented Jan 5, 2016

Removing child from front to back will lead to a problem of selected property when we remove option element. Because the second option will be selected when we remove the first option .
For example

var leftNode = h('select',null, [' ', users.map(function(user, index) {
    return h('option',{'selected': index == 0, 'key': Math.random()}, [user.name])
}), ' ']);

var rightNode = h('select',null, [' ', users.map(function(user, index) {
    return h('option',{'selected': index == 0, 'key': Math.random()}, [user.name])
}), ' ']);

var rootNode = render(leftNode);
var patches = diff(leftNode, rightNode);
var newRoot = patch(rootNode, patches);

The key property is random so it will append some new options to select and remove all old options and move new options to the front of the last VirtualText. The moving action has two steps: remove it and insert it. In this example we want to select the first option, but when we remove option from front to back all options's selected property will be true. After inserting the removed options the last option will be selected at last (Firefox is, but Chrome selects the second option weirdly).

For this case I think reorderChild method should remove child from back to front and insert child from front to back.

I made a pull request.

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