x-tag / core

The Heart of X-Tag
http://x-tag.github.io/
Other
1.25k stars 151 forks source link

xtag.queryChildren #166

Open positlabs opened 7 years ago

positlabs commented 7 years ago

What does xtag.queryChildren do?

Query only the direct children of an element with a provided selector.

<div id="dave">
    <div class="a">
        <div class="a sub"></div>
    </div>
</div>

If I did xtag.queryChildren(daveElement, '.a'), would it only select <div class="a"> and not <div class="a sub">?

I think the method name could be something like xtag.queryShallow()

OR...

It could be an internal method that is used by xtag.query(ELEMENT, SELECTOR, DEEP=true) when a boolean is passed. e.g. xtag.query(daveElement, '.a', false). This would simplify the API a bit.

csuwildcat commented 7 years ago

the queryChildren method was specifically for querying for selector matches among the immediate children of an element.

positlabs commented 7 years ago

@csuwildcat I get that, after typing it out. What do you think about simplifying the API, though?

I'm proposing we use xtag.query(ELEMENT, SELECTOR, DEEP=true), and removing xtag.queryChildren

csuwildcat commented 7 years ago

OK, here's how we could do this:

1) I can't ax the queryChildren method altogether in 1.x, because that's a breaking change 2) We can either redo queryChildren, or add functionality to query and use it within queryChildren to maintain its support 3) If we mod query, the last arg would be SHALLOW=FALSE by default, because the way you wrote it would default query to being child-level, which would break people using it the way it is now.

Thoughts?

positlabs commented 7 years ago

I like that approach. DEEP=true is the same as SHALLOW=false :)

I think SHALLOW=false is more explicit. Makes more sense to enable the shallow functionality, rather than disable the default.