-
Notifications
You must be signed in to change notification settings - Fork 668
Wrapper: find/findAll accepts ref options object #68
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
Conversation
|
src/lib/find-vnodes-by-ref.js
Outdated
export default function findVNodesByRef (vNode: VNode, refName: string): Array<VNode> { | ||
const nodes = findAllVNodes(vNode) | ||
const refFilteredNodes = nodes.filter(node => nodeMatchesRef(node, refName)) | ||
// Only return ref matches from top level vNode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my own understanding, why do we not do a recursive check here? Might be helpful to document in the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. This is because we want to emulate the exact selector functionality of wrappedComponent.$refs.myRef
.
If we do a recursive check, we may return a general result of wrappedComponent.$refs.someComponent.$refs.someComponent.$refs.myRef
when we only want to grab ref elements on the top-level wrapper itself. If you need a sub-component ref, you'd need to find the subcomponent and get the ref off of it explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks for the 💯 explanation!
const nodes = findAllVNodes(vNode) | ||
const filteredNodes = nodes.filter(node => nodeMatchesSelector(node, selector)) | ||
return removeDuplicateNodes(filteredNodes) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file includes all non-shared functionality from find-matching-vnodes
} | ||
}) | ||
return uniqueNodes | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file includes all shared functionality from find-vnodes-by-selector
and find-vnodes-by-ref
f7454b3
to
4e901ba
Compare
Ok, @eddyerburgh, so I know we're waiting on the discussion to resolve in #67 about whether or not the find by $ref functionality should be implemented for all methods that take a "Selector," but this PR implements that functionality in the case that we do decide to move forward with that. A few notes:
declare type Selector = string | Component but it looks like the global imports in
|
As you said, we should hold off until we've had more input from the community. But it looks great so far 🙂
|
re: 5. Yep, this is in the PR now. |
@eddyerburgh Do you have a link to the discussion that is happening around this? Would love to see this land! |
@kaicataldo here — #67 |
Hey @matt-oconnell , are you able to fix the merge conflicts? Then I'll merge |
883999a
to
754cee1
Compare
754cee1
to
6fcacfa
Compare
Ok, resolved 👍 |
Thanks @matt-oconnell 😀 |
This PR relates to #67
It adds the
.ref('someRefName')
method to the mainwrapper
.This returns a
WrapperArray
with wrappers for anyvnode
s that have the specified ref. Additionally,.ref
will only matchvnodes
with refs that exist on thewrapper.vm.$refs
.Do we want to just have a single
ref
function or do we want to split it intofindRefs
/findAllRefs
? Right now, this only returns a wrapper array.I haven't implemented tests yet because I wanted to make sure I was going in the right direction first.
The find-matching-vnodes-by-ref.js file that is added here uses some of the functionality from the existing find-matching-vnodes.js file. Should I pull out some of those functions into a more generic vnode traversal file or something?