Fix: sync store.pods[id].parent/position immediately on updates from anywhere #140
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I don't know what triggered such a horrible code reformation in
canvas
, actually this is just a very tiny modification. Eventually, I adopted another simpler optimization strategy other than what I proposed here. Please test it carefully before merging, it works on my side, but I'm not sure if any issue exists.A brief summary:
store.setPodPosition
andstore.setPodParent
, add a parameterdirty: bool
, setpod.dirty = pod.dirty | dirty
, that is, only triggers remote update request when the argumentdirty=true
. Note that we use|
(or) operation instead of=
(assign) to avoid a dirty pod cleaned by another localsetPodPosition
orsetPodParent
withdirty=false
before the update is synced to the DB.codeNode
andscopeNode
,useEffect
listens on the change of node position or change, callsetPodPosition
orsetPodParent
withdirty=false
whenever the corresponding position or parent node changes. We don't need to write the change to DB for now, but we must syncstore.pods
with the nodes in canvas.dirty=true
is only used when stopping dragging nodes (inonNodeDragStop
, that is, we only writes the update to DB when it is caused by operations by our current user. We don't need to write update pulled from the remote yjs server to the DB.Possible issue:
setPodPosition
continually, even though it doesn't changestore.pods[id].dirty
and no data is written to the DB. One solution to mitigate the update tostore
: take a look atdragging
as well, only updatestore.pods[id]
after the dragging stops, like:But I think the performance of dragging is acceptable now, if you feel uncomfortable with the performance in the future, the solution is just for reference.
close #138