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

Merge and update event: excessive event handler's calls #471

Open
ruscoder opened this issue Feb 2, 2017 · 2 comments
Open

Merge and update event: excessive event handler's calls #471

ruscoder opened this issue Feb 2, 2017 · 2 comments
Labels

Comments

@ruscoder
Copy link

ruscoder commented Feb 2, 2017

I found the odd behavior of update handler and merge.

Example:

const tree = new Baobab();
tree.set('test', {});
tree.select('test', 'value').set(1);

// Add update event handler
tree.select('test', 'value').on('update', (e) => console.log('update:', e.data.currentData, e.data.previousData)); 


tree.select('test', 'value').set(2)
// Update handler's output: update: 2 1

tree.select('test', 'value').set(2)
// Update handler wasn't called

tree.select('test', 'value').set(3)
// Update handler's output: update: 3 2

tree.select('test', 'anothervalue').set(1);
// Update handler wasn't called because it is another cursor

Before, everything was OK. Update handler was called only when data was changed.

tree.select('test').merge({ 'anothervalue': 1});
// Update handler's output: update: 3 3

tree.select('test').merge({ 'anothervalue': 1});
// Update handler's output: update: 3 3

I think it is bad behavior because data wasn't changed and cursor ['test', 'value'] always had the same value.

What do you think about this?

@Yomguithereal
Copy link
Owner

I am not sure to understand your case but what you need to know is that Baobab never perform data diff for performance reasons but instead compare paths. In the merge case, you edit the parent path, so I cannot infer that the underlying values have change or not, hence the event.

@Yomguithereal
Copy link
Owner

But I might change some handler strategies in the future.

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

No branches or pull requests

2 participants