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

.set path error #2

Open
slimbuck opened this issue Sep 4, 2021 · 0 comments
Open

.set path error #2

slimbuck opened this issue Sep 4, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@slimbuck
Copy link
Member

slimbuck commented Sep 4, 2021

There seems to be a bug with paths in the Observer.

The following code:

const o = new Observer({});
o.on('*:set', (path, value, oldValue) => {
    console.log(`${path} = ${JSON.stringify(value)}`);
});
o.set('theParent.0.child', { x: 1, y: 2 });

Gives output:

theParent.0.child.child.x = 1
theParent.0.child.child.y = 2
theParent.0.child.child = {"x":1,"y":2}

Notice the third path should be theParent.0.child.

Looking at Observer's internal node tree suggests that all paths set here are incorrect. I believe the line should read:

    _path: keys.slice(0, i).join('.')

Interestingly, if theParent.0.child is set to an atomic value before assigning an object then the resulting paths appear correct. However in this case '*:set' events don't propagate up the parent tree.

@willeastcott willeastcott added the bug Something isn't working label Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants