Open johnrees opened 5 years ago
Sounds good to me, though I'm not sure how it would be pulled off since arrays don't really have a "swap" method, so it might be hard to generate such patches for a single operation.
By the way, does it only apply to arrays?
For me detach
+ patch add
worked well as move
operation substitute
Feature request
Is your feature request related to a problem? Please describe.
The application I am currently working on uses a very large tree structure. I often need to move nodes around and patches currently delete the node (and all of its descendants) then recreate it in the new location. It is a collaborative editor and these patches are broadcast via websockets and it seems wasteful to need to recreate large sub-trees each time a node is moved.
Describe the solution you'd like
I would like to use the move operation instead http://jsonpatch.com/#move
Describe alternatives you've considered
I've hacked together a workaround/example here https://codesandbox.io/s/18xjlrnz14
Everything is in the console, basically it collects
patches
in anarray
then when theonSnapshot
is triggered it looks through the array to see if there are anyremove+add
operations with the same ID, and replaces them with a singlemove
operation.In the example this tree is created...
then maggie and homer are moved and (moved) is appended to their names
using regular MST the patch/inverse operations for moving involve removing and adding the node. This is to move homer and append (moved) to his name.
my workaround replaces the above operations with
Additional context
Are you willing to (attempt) a PR?
Maybe