Skip to content

Entity renderers should be given more data on render #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thibaudcolas opened this issue Mar 1, 2018 · 1 comment · Fixed by #124
Closed

Entity renderers should be given more data on render #91

thibaudcolas opened this issue Mar 1, 2018 · 1 comment · Fixed by #124
Labels
enhancement New feature or request
Milestone

Comments

@thibaudcolas
Copy link
Collaborator

thibaudcolas commented Mar 1, 2018

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.

@thibaudcolas thibaudcolas added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Mar 1, 2018
@thibaudcolas thibaudcolas added this to the v3.0.0 milestone Mar 1, 2018
@thibaudcolas thibaudcolas changed the title entity Entity renderers should be given more data on render Mar 1, 2018
@thibaudcolas thibaudcolas modified the milestones: v3.0.0, Nice to have Sep 26, 2019
@thibaudcolas thibaudcolas added good first issue Good for newcomers help wanted Extra attention is needed hacktoberfest https://hacktoberfest.digitalocean.com/ and removed good first issue Good for newcomers help wanted Extra attention is needed labels Sep 26, 2019
@thibaudcolas
Copy link
Collaborator Author

If anyone is interested in contributing to this, I would welcome a pull request to implement this in a backwards-compatible way (the change just doesn’t feel worth breaking changes on its own).

We could use the following structure:

 props = entity_details['data'].copy() 
 props['entity'] = { 
     'type': entity_details['type'], 
+     'key': key, 
+     'entity': entity_details, 
+     'block': block, 
 } 

Then when we want to make this nicer / more future-proof as a breaking change, we can simply set props to equal that dict.

thibaudcolas added a commit that referenced this issue Jan 1, 2020
thibaudcolas added a commit that referenced this issue Jan 1, 2020
@thibaudcolas thibaudcolas removed good first issue Good for newcomers hacktoberfest https://hacktoberfest.digitalocean.com/ help wanted Extra attention is needed labels Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant