Skip to content

.set path error #2

Description

@slimbuck

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions