Support complex / deep / nested attributes with partial updates #4000
alecgibson
started this conversation in
Ideas
Replies: 2 comments
-
Original raised as a Pull Request: slab/delta#48 I've added some thoughts on Backwards compatibility: Possible mitigations
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Interesting information. I am new to maintaining a website and its design. Therefore, in order to attract the audience and get an advanced website, I used front end development services. Specialists using the latest trends and technologies helped create aesthetically attractive websites. It fits my business goals perfectly. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Originally raised here: Original raised as a Pull Request: slab/delta#48
This change proposes support for complex attributes, which might have arbitrarily nested properties:
Motivation
The particular use case with which this was written in mind is the addition of comments to Quill. That is, the ability to select part of a document, and add some extra information about that selection.
Comments can be applied to arbitrary content, so cannot be represented as an embed (for example). They naturally belong to the attributes:
The issue with comments is that multiple comments may exist on the same range:
These cannot be "flattened" (ie have the comments IDs as the attributes), because the IDs are arbitrary strings, which:
Any other metadata-like attributes may also benefit from this sort of deeply nested structure. For example, a naive git-blame-like feature might look like:
Implementation
The implementation would recursive, and each depth of attributes is treated similarly to the top level. In particular:
null
will remove a propertynull
The thing that this allows is updating a nested property without affected the rest of the structure (in the same way that you can apply
bold
at the root without removingitalic
):Arrays
Note that arrays are out-of-scope of this change. Their behaviour is not well defined when composing deltas together, and they are treated as if they are primitive values (ie they directly overwrite one another, rather than attempt a deep change).
Quill integration
Quill will not natively support these changes, and further work will be required if this capability is to be adopted there. Given that Quill v2 is currently in development, this may be a good time to do this work, if desirable.
In particular:
format()
methods need tocompose
values rather than simply overwritemerge()
methods need to perform deep equality checks, rather than object reference checksNote that Quill can currently support these complex attributes, but only with blots that override the above methods.
Backwards compatibility
This change is not technically backwards-compatible. If anyone is already using deeply nested attributes and relying on the current all-or-nothing behaviour, then this change will break their code.
Possible mitigations
$complex
?{insert: 'foo', attributes: {...}, complex: {...}}
?Registry
/declared as aBlot
property/extend aComplexBlot
?Beta Was this translation helpful? Give feedback.
All reactions