Skip to content
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

html.tag() should merge attributes lazily, when needed #331

Open
towerofnix opened this issue Nov 19, 2023 · 1 comment
Open

html.tag() should merge attributes lazily, when needed #331

towerofnix opened this issue Nov 19, 2023 · 1 comment
Labels
type: groundworks Changes are foundational to further issues & code work

Comments

@towerofnix
Copy link
Member

So we currently don't have any magical caching for content functions, wherein the same output of generate is reused for multiple arrangements of its slots. But that's coming, eventually, and when we merge attributes, we need to do so conscientiously!

Immediate merging is appropriate if multiple object literals are listed in a row. For example:

html.tag('foo',
  {literalAttributes1},
  {literalAttributes2},
  mysteriousOtherValue,
  {literalAttributes3})

The first and second attribute sets should be combined immediately (at call of html.tag), but mysteriousOtherValue should be left exactly as it is - in place between the combined attributes above and {literalAttributes3} below, which also isn't combined with anything. (Unless another object literal were to follow it.)

The details of mysteriousOtherValue aren't important, only that it can be distinguished from object literals - it's likely to be either a symbol or an object with a global symbol attached.

Lazy combining should happen at time of toString() (or analogous serialization) - and it should behave just like immediate merging, only using the now-available slot values, in place as if they were just another object literal.

This isn't a pressing issue since it's not implemented, just worth keeping in mind when coming back around to cached or thread-transferred content functions.

@towerofnix
Copy link
Member Author

#330 (comment)

See #331: We should take care to implement merging in a generic, top-down manner - basically like the syntax for Object.assign. This should be separate from the main tag/attributes constructor, so it's easier to compose with a separate "only combine certain sets of attributes at once" behavior later on.

#351 (comment)

At the moment, Attributes.add and its various helpers all operate on a single live object, but that's only for the sake of mutation. Later on, the essential algorithm should be able to be refactored without much modification for #331.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: groundworks Changes are foundational to further issues & code work
Projects
None yet
Development

No branches or pull requests

1 participant