Yomguithereal / baobab

JavaScript & TypeScript persistent and optionally immutable data tree with cursors.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Merge and monkey issue

ruscoder opened this issue · comments

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({});

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.