Do not use element reference in DifferItemInsert
and DifferItemRemove
#15800
Labels
package:engine
squad:collaboration
Issue to be handled by the Collaboration team.
type:improvement
This issue reports a possible enhancement of an existing feature.
Milestone
📝 Provide a description of the improvement
Recently, we introduced
_element
property forDifferItemInsert
andDifferItemRemove
. It was done in #15649.The differ represents all changes as insertions, deletions and attribute changes. So, the rename operation is represented by two changes: remove + insert. But we had no good way to link such two changes together and figure out that it was actually a rename. We also have "refresh" mechanism, which forces an element to reconvert, by adding remove+insert changes.
And we needed this to solve some problems regarding track changes, to understand if a user renamed an element, or removed+inserted an element, as we want to present such operations in a different way.
To solve that, we introduced
_element
property, which was a reference to the changed element. Now for eachDifferItemInsert
entry you can look if there is correspondingDifferItemRemove
entry.The PR was accepted but the solution was not received positively, and I can understand why. We decided to use it anyway, but implement
_element
as internal (private) property and fix it later. We don't like this solution because we made a hard effort earlier to avoid passing the reference in diff items. Our idea was that diff items should have all the information to handle the change given in simple form. You should not need to use the element reference.It is important for remove entries -- we don't want people to base on references when handling remove entries, as it will lead to incorrect results. The element reference in remove entry will be outdated, especially when it comes to its position. The deletion position was in the model (the element position before it was removed), while the element's actual position will be in the graveyard root. Also, the element could have been renamed, or change its attributes, and the reference will have the new values, not the old ones. So, long story short, if we can avoid it, we will still make an effort not to pass the element reference in diff items.
Also, it is confusing now, that we have
name
andattributes
next to "full" element reference. Why/when should I use this or that? Is there difference? If no, why we havename
andattributes
? And so on...So, instead of
_element
we need to propose something else. My proposal is:For
DiffItemInsert
:Where action is
refresh
orrename
when that was the original "trigger", whileinsert
is the default.For
DiffItemRemove
justaction
, asattributes
andname
are already in "before" state. Of course action should be'remove' | 'refresh' | 'rename'
.I am not super happy with
before
name though, so I am open to suggestions if you have something more fitting.The text was updated successfully, but these errors were encountered: