Open leontrolski opened 2 years ago
So map1
would be an mutable object which could collect the mutations, if I understand correct. It would be a much nicer syntax, but the problem is not sure how engines could optimized it.
And what happened alter (map1) { setTimeout(() => map1.b = 50) }
? I supposed it should throw?
Sorry for the delay @hax! I'm not sure it would need to throw in that circumstance.
The await
block would return whatever value map1
had immediately after running the code in the block, anything that is pushed to happen later in the event loop would just be ignored.
Considering an async
variant is worthwhile though:
const map2 = async alter (map1) {
map1.b = await someApiCall()
}
would suffice.
Looking at the examples, the
immer
approach is at the very least shorter, what about baking in the approach but with a newalter
keyword?Some advantages would be:
alter {}
blocks where there were warnings.immer
would be the interpreter would be able to do structural sharing of eg. long arrays of numbers.