remove the `data` dictionaries
See original GitHub issueDo you want to request a feature or report a bug?
Debt / improvement.
What’s the current behavior?
Right now many objects in Slate have a data
dictionary where you can store userland metadata that Slate doesn’t need to concern itself with. This works fine for now, and with Immutable.js it’s the only reasonable way to do it.
However, once we switch to plain JSON objects, and are using an interface-based API, I think it will be better to allow userland to store metadata at the top level of any objects. For example:
{
type: 'link',
nodes: [...],
url: 'https://example.com',
}
Instead of needing to nest it inside data.url
, the url
property can live at the top level. And the object still implements the Element
interface so everything works as expected.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:18 (16 by maintainers)
Top Results From Across the Web
Delete data dictionary entry - MATLAB deleteEntry - MathWorks
deleteEntry( sectionObj , entryName ,'DataSource', dictionaryName ) deletes an entry that is defined in the data dictionary DictionaryName . Use this syntax to ......
Read more >Delete Data Dictionary (DLTDTADCT) - IBM
The Delete Data Dictionary (DLTDTADCT) command deletes a data dictionary. All program described files linked to definitions in the dictionary must be ...
Read more >Methods for deleting database dictionary records - Micro Focus
Best practice: Provide Service Manager table create-alter-drop-rights to the RDBMS, and delete an existing database dictionary record. Service Manager deletes ...
Read more >Removing a Table from a Data Dictionary
If you want to erase a table that you have removed from the data dictionary in this way, you can do so by...
Read more >How to remove items from a dictionary in Python - Educative.io
The pop method uses the keyword from the given dictionary to remove an item from that dictionary. The pop method is similar to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Panicked when I read “remove data dictionaries” but the alternative sounds good.
@ssalka good question! That is definitely the tradeoff here. I don’t take it lightly, but I think as I’ve been working through some of the changes for #2495 I’ve slightly changed how I think about Slate’s data model. I’ll explain how my thoughts have evolved since the original decision to keep them separate and you can see what you think…
Before, we’ve had three domain layers:
Up to now this has worked, since keeping them separate is guaranteed not to clash—and that is important. And for Immutable.js it’s actually required, because it can’t handle dynamic properties.
But it’s not without tradeoffs.
It adds complexity to have a nested
data
object, and the API for retrieving things from the nested object becomes awkward.And when you end up serializing your data into your database, or presenting it externally to someone who has no knowledge that you use Slate, it feels weird to have the separation in where data lives, when all of it is “your” data. You likely merge the properties in your custom serialization layer, or just absorb the awkwardness (and extra data size bloat in the case that
data
is empty) as a cost of doing business.Not only that, but if you are building a more advanced editor where you need the third layer of namespacing (eg.
node.data.properties
, but it can be named anything), the API for retrieving information from that third layer is especially awkward. And the distinction between them to end users is not clear.After, we have just two domain layers:
In the updated data model, Slate changes the way it thinks about the data, to being interface-based. As long as your data implements the interface it expects, you can store anything in it.
It’s kind of like Slate acting on your own custom data model instead. So instead of needing a
node.data
dictionary to hold dynamic properties, you can store them at the top level. But at the cost of not being able to use the special-casednodes
property.This also unlocks possibilities that previously would have been awkward… for example storing an
node.id
property on each node can be kept at the top-level, instead of the awkwardnode.data.id
, which feels weird for such a canonical property to live in a nested dictionary.Even further, I’m experimenting with the
node.type
property actually living in developer-land. Slate doesn’t technically need to know abouttype
to do its job—in fact it’s always been type-averse in not wanting to set a default for example. You could call itkind
, orname
, or whatever made sense for your use case. Or if you have only one type of node, you could leave it out altogether.So the interface for nodes might just require:
You end up being able to describe things in a way that feels very natural when exposed to an end user of your API:
We’ve also removed the need for
object: 'block'
orobject: 'inline'
, since those are now part of your own Slate editor’s runtime schema configuration. For example, you could tell it to automatically treat any node with propertytype: 'link'
as an inline.But, without the nested data attribute, you could decide that for your data model it actually makes sense to hard-code the
object
property: