-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "[WIP] Support for ref callback (#4807)"
This reverts commit acec8db.
- Loading branch information
Showing
5 changed files
with
32 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,44 @@ | ||
/* @flow */ | ||
|
||
import { remove } from 'shared/util' | ||
|
||
export default { | ||
create: registerRef, | ||
update: registerRef | ||
create (_: any, vnode: VNodeWithData) { | ||
registerRef(vnode) | ||
}, | ||
update (oldVnode: VNodeWithData, vnode: VNodeWithData) { | ||
if (oldVnode.data.ref !== vnode.data.ref) { | ||
registerRef(oldVnode, true) | ||
registerRef(vnode) | ||
} | ||
}, | ||
destroy (vnode: VNodeWithData) { | ||
registerRef(vnode, true) | ||
} | ||
} | ||
|
||
export function registerRef (_: any, vnode: VNodeWithData) { | ||
export function registerRef (vnode: VNodeWithData, isRemoval: ?boolean) { | ||
const key = vnode.data.ref | ||
if (!key) return | ||
|
||
const vm = vnode.context | ||
const ref = vnode.componentInstance || vnode.elm | ||
const refs = vnode.context.$refs | ||
|
||
if (typeof key === 'function') { | ||
key(ref) | ||
} else if (vnode.data.refInFor) { | ||
const refArray = refs[key] | ||
if (Array.isArray(refArray)) { | ||
if (refArray.indexOf(ref) < 0) { | ||
refArray.push(ref) | ||
} | ||
} else { | ||
refs[key] = [ref] | ||
const refs = vm.$refs | ||
if (isRemoval) { | ||
if (Array.isArray(refs[key])) { | ||
remove(refs[key], ref) | ||
} else if (refs[key] === ref) { | ||
refs[key] = undefined | ||
} | ||
} else { | ||
refs[key] = ref | ||
} | ||
} | ||
|
||
export function resetRefs (refs: Refs): Refs { | ||
const res = {} | ||
// keep existing v-for ref arrays even if empty | ||
for (const key in refs) { | ||
if (Array.isArray(refs[key])) { | ||
res[key] = [] | ||
if (vnode.data.refInFor) { | ||
if (Array.isArray(refs[key]) && refs[key].indexOf(ref) < 0) { | ||
refs[key].push(ref) | ||
} else { | ||
refs[key] = [ref] | ||
} | ||
} else { | ||
refs[key] = ref | ||
} | ||
} | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters