You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When synchronizing a Yjs doc with an external data structure, it'd be great if there was a way to transform a Yjs type into an immutable data structure so that we can implement memoization on it.
With Yjs, we initially implemented a solution using:
const mutationKeys: WeakMap<YJSInput, number> = new WeakMap();
/**
* Observe mutations on a Yjs input and return a number that increments on each mutation.
*/
function getYMutationClock(input): number {
observeMutations(input);
return mutationKeys.get(input) || 0;
}
function observeMutations(input: YJSInput) {
if (mutationKeys.has(input)) {
return;
}
mutationKeys.set(input, 0);
input.observeDeep(() => {
const current = mutationKeys.get(input) || 0;
mutationKeys.set(input, current + 1);
});
}
But it seems to be inconsistent and corrupts the cache.
Any suggestion on alternatives ?
The text was updated successfully, but these errors were encountered:
When synchronizing a Yjs doc with an external data structure, it'd be great if there was a way to transform a Yjs type into an immutable data structure so that we can implement memoization on it.
For example liveblocks has
toImmutable
on all its low level types: https://github.com/liveblocks/liveblocks/blob/f4096d55f16c237a4718a5dc7ec5018e4cbdf438/packages/liveblocks-core/src/crdts/AbstractCrdt.ts#L363It's really useful as a WeakMap can be used to cache transformation from these values to a computed value.
With Yjs, we initially implemented a solution using:
But it seems to be inconsistent and corrupts the cache.
Any suggestion on alternatives ?
The text was updated successfully, but these errors were encountered: