Closed nlepage closed 6 years ago
IMO the current behavior is correct.
But it would be nice to have some mechanism to achieve a "lazy" get inside a slice.
ES version:
{
...obj,
arr: obj.arr.map(({ nested1, nested2, ...rest }) => ({
...rest,
nested1: {
...nested1,
val: nested2.val,
},
nested2,
}))
}
Very easy with immer:
produce(
obj,
draft => draft.arr.forEach(({ nested1, nested2 }) => { nested1.val = nested2.val }),
)
and of course with qim :heart: (not sure if this is the simplest way):
apply(
['arr', $each, $setContext('val2', select(['nested2', 'val'])), 'nested1', 'val'],
(_, { val2 }) => val2[0],
obj,
)
In fact there is one way to do it with immutad●t:
update(
obj,
'arr[:]',
set('nested1.val', get('nested2.val')),
)
Maybe this is sufficient... I think I need some sleep...
In fact, immutad●t is the shortest...
Closing this
The "lazy" get is unusable with slices: