Description
Following up this discussion here: #1490. Read that for context!
I think we should consider splitting find
into two methods.
find
. This will only work for DOM nodes. It will use thequerySelector
syntax.findComponent
. This can find a Vue component. By ref, name, etc.
Usage
- ✅
find("#foo")
- ✅
findComponent(Bar)
- ✅
findComponent(Bar).findComponent(Foo)
- ❌
findComponent(Bar).find("#foo")
- ❌
find("#foo").findComponent(Bar)
The reason I think we should split these is they are really different. One is searching the DOM for nodes; the other is searching for vnodes in Vue's virtual dom. I think this would remove a lot of caveats and simplify things.
I think not allowing them to mix will make tests more simple. Simple is good. findComponent
tells the reader you are interested in the component; find
shows you are interested in the DOM and what is rendered.
We can either make this change now (with a deprecation warning) to be removed in v1 (hopefully soon). Alternatively, we keep this current behavior, and for v2 (which will be Vue 3 support) we change to this new API.
As an aside, I would be in favor of making findComponent
more simple - currently you can find by name/ref/component... can we just pick one? Rather than go with the classic Perl motto "There is more than one way to do things" I much prefer the Python motto "There should be one-- and preferably only one --obvious way to do it". Anyway, let's focus on the splitting of the APIs for now.