Re: [csswg-drafts] [css-pseudo-4] Proposal: Highlight API (#4307)

> I'm a little worried about the ergonomics of the API for adding a range to a particular named group when the caller is not sure if that group already exists. 

Yeah, it'd be:

```js
if(!CSS.highlights.has("foo")) {
  CSS.highlights.set("foo", new HighlightRangeGroup);
}
CSS.highlights.get("foo").add(myRange);
```

This is assuming that the HighlightRangeGroup is live and immediately responds to changes. Depending on semantics, it might be more like TypedOM and require you to re-set it before it sees the change, in which case the code could look like:

```js
CSS.highlights.set("foo",
  (CSS.highlights.get("foo") || new HighlightRangeGroup)
  .add(anotherRange));
```

So yeah, a little painful.

---

That said, in practice, I'm not sure why a page would run into this situation. If they're doing highlighting, presumably they'd create and register the highlight group sometime early in the page lifecycle, and just hold onto it and modify the set as they need to change things?

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4307#issuecomment-531645817 using your GitHub account

Received on Monday, 16 September 2019 05:30:48 UTC