Yomguithereal / baobab

JavaScript & TypeScript persistent and optionally immutable data tree with cursors.
MIT License
3.15k stars 117 forks source link

tree.set and pathes #416

Closed markuplab closed 8 years ago

markuplab commented 8 years ago

Hello @Yomguithereal! I have question about tree.set / cursor.set.

state.set(['array', { id: 10 }, 'field'], value)

When we use path with "find" logic, it's convert it to string '[object_Object]' and use it as key. It's planned? If planned, i think we must analyze paths with find logic, and work like it tree.get

Yomguithereal commented 8 years ago

Hello @markuplab. You shouldn't do the following:

state.set(['array', { id: 10 }, 'field', value]);

But this:

state.set(['array', { id: 10 }, 'field'], value);

Because your first example is saying: set the whole state to be the array I give you.

But the fact that it is cast to string is weird. Can you build a full use case so I can try to debug it, please?

markuplab commented 8 years ago

Sorry, it's error in message.

var tree = new Baobab({
    x: [
        { id: 10, hello: 'world' }
  ]
});

tree.set(['x', { id: 10 }, 'field', 'some'], 'value');
console.log(tree.get());

2015-12-29 23 20 01

But this code work correct:

tree.set(['x', { id: 10 }, 'field'], 'value');

2015-12-29 23 21 20

Yomguithereal commented 8 years ago

Ok, I see now. Thanks @markuplab. Will fix that asap.

Yomguithereal commented 8 years ago

This is more profound than I initially thought. Will need some time to fix this.

Yomguithereal commented 8 years ago

This should be fixed now. Thanks @markuplab and sorry for the delay.