question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add `Decoration` object instead of re-using `Range`

See original GitHub issue

Right now for value.decorations we’re re-using the Range objects, because they refer to two points with marks. But I think there is more we’ll want to do with decorations, and as currently architected any new properties that decorations support have to be added to Range which is awkward.

Instead, I think we should separate out decorations into their own Decoration model:

new Decoration({
  anchorKey,
  anchorOffset,
  focusKey,
  focusOffset,
  marks,
})

This would allow us to add a data property holding arbitrary end-user data. And a key property holding a unique identifier to identify the decorations across renders/updates.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
ianstormtaylorcommented, Jun 15, 2018

@zhujinxuan yup, we would introduce a renderDecoration prop for rendering them. The difference is that they are applied to ranges of the document without affecting the document’s data directly, versus marks which are applied to the text itself.

0reactions
jasonphillipscommented, Jun 15, 2018
  • It would be good to be able to reference decorations easily, to be able to remove or update them as things change. The current implementation just has a value.decorations which isn’t keyed by anything, or typed in any way, so plugins can’t know which ones to remove/update if the state changes.
  • It would be good to be able to associate arbitrary data with decorations. Right now technically this is possible via using range.marks, but it feels hacky.

These are issues I’ve had to work around recently (basically: updating a large set of decorations essentially requires dropping / rebuilding them since no consistent id exists; and we attach data to them but it ends up looking like decoration.marks[0].data everywhere, which isn’t pretty). So I think a new type of Object to handle these in a more focused way than Range+Mark sounds great.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reusing instances of objects vs creating new ones with every ...
Explanations: "reusing": overwriting the values of an old instance with new values, effectively changing the state of the instance. "new ones/ ...
Read more >
Primer on Python Decorators
They can be reused. They can decorate functions with arguments and return values. They can use @functools.wraps to look more like the decorated...
Read more >
Example: Decorations - CodeMirror
The range method on these objects gives you an actual decorated range, which holds both the type and a pair of from /...
Read more >
Create components to reuse in designs - Figma Help Center
You can create components from any layers or objects you've designed. These could be a whole range of things like buttons, icons, layouts,...
Read more >
Before You Recycle, Choose to Reuse
This publication for individuals and groups describes how to reduce waste by reusing materials, including clothing and household items.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found