feat: add option to skip write when possible#10
Conversation
| /** | ||
| * @internal Symbol used to track if the object has been mutated | ||
| */ | ||
| export const _MUTATED = Symbol("mutated"); | ||
|
|
||
| /** | ||
| * @internal Symbol used to track if the object is being tracked | ||
| */ | ||
| export const _TRACKED = Symbol("tracked"); |
There was a problem hiding this comment.
Can we leave them internal, or is there a good reason to export them?
| /** | |
| * @internal Symbol used to track if the object has been mutated | |
| */ | |
| export const _MUTATED = Symbol("mutated"); | |
| /** | |
| * @internal Symbol used to track if the object is being tracked | |
| */ | |
| export const _TRACKED = Symbol("tracked"); | |
| /** | |
| * @internal Symbol used to track if the object has been mutated | |
| */ | |
| const _MUTATED = Symbol("mutated"); | |
| /** | |
| * @internal Symbol used to track if the object is being tracked | |
| */ | |
| const _TRACKED = Symbol("tracked"); |
There was a problem hiding this comment.
We use them for testing.
I don't know if there's another way of exposing these to tests but not to the public API.
There was a problem hiding this comment.
I think we can use Symbol.for then
There was a problem hiding this comment.
Or just make sure we only export things internally but don't leak it to package consumers :)
| return object as Mutatable<T>; | ||
| } | ||
|
|
||
| const proxyCache = new WeakMap(); |
There was a problem hiding this comment.
How hard would it be to tie the cache to a property session instead? That would feel like a more obvious strategy to manage the lifetime of these objects in memory
There was a problem hiding this comment.
I don't think it'd be that hard, but it's not obvious to me why we'd want to do it, sorry.
There was a problem hiding this comment.
I find it hard to reason about the lifecycle of memory when there are different references to the objects, and only some of them prevent it from being garbage-collected. This is especially so if there is an obvious way to structure that code such that the memory is directly tied to the stack, which makes it very obvious how long the objects live. But if you have strong opinions about keeping it in a WeakMap, then I'll be able to wrap my head around it :)
I need help in figuring out other possible edge cases or caveats so we can add tests for them and, ultimately, document them.
Usage:
Closes #3