Problem/Motivation

When adding new items to the DOM, its possible to add multiple adjacent elements as part of a DocumentFragment. This allows adding to a list of items, for example, without complicating DOM sibling traversal with "previousElementSibling", et al.

However, the once function does not allow the use of DocumentFragments as the "context" from which to select elements.

Steps to reproduce

1. Create a new DocumentFragment()
2. Attempt to select items with the new fragment as the context
3. Get new type error: "The element must be an instance of Element"

Proposed resolution

We don't actually want to check if context is an element. Instead we can check one of two things:

1. if the item is an instance of Document, DocumentFragment, or Element. (classes with a querySelectorAll method)
2. if the typeof item.querySelectorAll is a function

Remaining tasks

- Select a solution
- Do it

User interface changes

None

API changes

The API would allow more data types to be used as "context" without impacting backwards compatibility

Data model changes

None

Issue fork once-3320496

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

andy-blum created an issue. See original summary.

andy-blum’s picture

Issue summary: View changes

update IS

andy-blum’s picture

Status: Active » Needs review

Two issue branches are open, but I can't figure out how to make MRs out of them.

nod_’s picture

Ok with option 1

nod_’s picture

Status: Needs review » Needs work
nod_’s picture

To be in line with the rest of the code we should throw an error as well

andy-blum’s picture

Status: Needs work » Needs review
nod_’s picture

Status: Needs review » Needs work

few things to fix.

Ideally we'd have tests to make sure calls on documentFragment keep working over time

andy-blum’s picture

Status: Needs work » Needs review
andy-blum’s picture

I've been unable to run the tests locally

nod_’s picture

Status: Needs review » Reviewed & tested by the community

was able to run the tests with yarn web-test-runner, they pass.

I'll commit next week if justafish doesn't beat me to it :)

Thanks!

  • nod_ committed 56f832e on 1.0.x authored by andy-blum
    Issue #3320496 by andy-blum, nod_: context should allow use of...
nod_’s picture

Status: Reviewed & tested by the community » Fixed

Thanks :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.