Yomguithereal / baobab

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

Merge and monkey issue #465

Open ruscoder opened 7 years ago

ruscoder commented 7 years ago

I caught some problem when I tried to merge the following object with nested monkey:

tree = new Baobab({ a: 1, nested: [] })
tree.set(['nested', '0', 'dynamic'], Baobab.monkey(['a'], (a) => a + 1));
tree.merge({});

Result: Uncaught TypeError: Cannot set property dynamic of #<Object> which has only a getter(…)

But next example works as expected:

tree = new Baobab({ a: 1, nested: {} })
tree.set(['nested', 'dynamic'], Baobab.monkey(['a'], (a) => a + 1));
tree.merge({});
Yomguithereal commented 7 years ago

Hello @ruscoder. This is a bug I need to investigate indeed. However I see that in your example you seem to create monkeys in a path nested beneath an array. I would advise not to do this for performance reasons.