Skip to content

Commit

Permalink
fix: tree extract the public method
Browse files Browse the repository at this point in the history
  • Loading branch information
Lydanne committed Sep 24, 2020
1 parent 157b543 commit 3703f77
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/tree/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
import { Tree } from './entity/Tree'
import ElTreeNode from './TreeNode.vue'
import { t } from 'element-ui/src/locale'
import { extractMethods, isFunction } from './libs/util'
import { isFunction } from 'element-ui/src/utils/types'
import { extractMethods } from './libs/util'
import {
reactive,
Expand Down
14 changes: 4 additions & 10 deletions packages/tree/libs/util.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
export function isArray(value) {
return value instanceof Array
}
export function isObject(value) {
return value instanceof Object && !(value instanceof Array)
}
export function isFunction(value) {
return value instanceof Function
}
import { isArray, isObject } from 'element-ui/src/utils/types'

/**
* Deep traversal of the object
* @param {object} target
Expand Down Expand Up @@ -47,9 +40,10 @@ export function nodeEach(
{ childKey = 'children', root = null } = {}
) {
const dfs = (node) => {
if (!isObject(node)) {
if (!isObject(node) || isArray(node)) {
return
}

const child = node[childKey] || []

for (let i = 0; i < child.length; i++) {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export function isObject(obj) {
return Object.prototype.toString.call(obj) === '[object Object]'
}

export function isArray(value) {
return value instanceof Array
}
export function isHtmlElement(node) {
return node && node.nodeType === Node.ELEMENT_NODE
}
Expand Down

0 comments on commit 3703f77

Please sign in to comment.