Skip to content

Entity renderers should be given more data on render #91

@thibaudcolas

Description

@thibaudcolas

Follow-up to #87. At the moment, entity components are only given a small amount of data about an entity for rendering:

props = entity_details['data'].copy()
props['entity'] = {
'type': entity_details['type'],
}
nodes = DOM.create_element()
for n in self.element_stack:
DOM.append_child(nodes, n)
elt = DOM.create_element(opts.element, props, nodes)

There are a few more problems here:

  • The shape of the props is different than how this is stored in the Draft.js entityMap.
  • The entity data is given as the top-level props, which makes it impossible to add extra props without risking overwriting the entity data (say if the entity has a field called type that does something different from the entity type).

We should refactor this to something like:

props = {}
props['entity'] = entity_details
props['entity']['key'] = key
props['block'] = block
props['blocks'] = blocks
# (Potentially the `entity_range` as well?)

This way, it's easy to add arbitrary props without risking overwrites. The components get full access to the entity data, mutability, type, and key. And to the current block and blocks list, like styles, decorators, blocks.

Compared to the changes introduced in #90, this would be a breaking change, so should be considered carefully. Users of the exporter will have to rewrite their renderers slightly to use the new props shape.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions