-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Milestone
Description
Thanks to jsonpatch
all our apps assume that tree changes come asynchronously. So going synchronous is in fact the breaking change. We can leverage this and make JSONPatcherProxy asynchronous. Mind the fact that this will not create patches order problems! Because the changes are recorded synchronously and no change can go unnoticed. The asynchronous part only covers calling the callback (sending to the socket), the recording part remains synchronous.
Pros:
- Big sync changes (eg: loops) will not kill performance by triggering
WS.send
a lot. They will be batched into one patch. - We can very easily track move operation with O(1) performance! Given that we have a map that contains all the objects in our tree that we can look up with O(1) speed, we can try move operation very easily.
- Summation of patches comes naturally.
- We will be able to squash redundant changes. Now (
obj.size = 1; obj.size = 2
) would create two operations in the same patch, one of them is redundant. But we can compress them using my lib (I wrote it this weekend in my free time, I don't mind moving to Palindrom organisation if you agree to invest time in it). - No breaking changes in all our apps.
- We can make it an optional flag with no hassle whatsoever.
Cons:
- Will take some time to re-write the tests to deal with the async manner.
- Could be less semantic. Synchronous code is always more predictable.
Implementation:
instead of calling the callback with every change, we can:
clearTimeout(lastTimeout);
patch.push({operation that happened});
lastTimeout = setTimeout(emitPatch, 1, patch);
Yup, that simple.
warpech
Metadata
Metadata
Assignees
Labels
No labels