(options)
| 43 | |
| 44 | export default class Node { |
| 45 | constructor(options) { |
| 46 | this.id = nodeIdSeed++; |
| 47 | this.text = null; |
| 48 | this.checked = false; |
| 49 | this.indeterminate = false; |
| 50 | this.data = null; |
| 51 | this.expanded = false; |
| 52 | this.parent = null; |
| 53 | this.visible = true; |
| 54 | |
| 55 | for (let name in options) { |
| 56 | if (options.hasOwnProperty(name)) { |
| 57 | this[name] = options[name]; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // internal |
| 62 | this.level = 0; |
| 63 | this.loaded = false; |
| 64 | this.childNodes = []; |
| 65 | this.loading = false; |
| 66 | |
| 67 | if (this.parent) { |
| 68 | this.level = this.parent.level + 1; |
| 69 | } |
| 70 | |
| 71 | const store = this.store; |
| 72 | if (!store) { |
| 73 | throw new Error('[Node]store is required!'); |
| 74 | } |
| 75 | store.registerNode(this); |
| 76 | |
| 77 | const props = store.props; |
| 78 | if (props && typeof props.isLeaf !== 'undefined') { |
| 79 | const isLeaf = getPropertyFromData(this, 'isLeaf'); |
| 80 | if (typeof isLeaf === 'boolean') { |
| 81 | this.isLeafByUser = isLeaf; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if (store.lazy !== true && this.data) { |
| 86 | this.setData(this.data); |
| 87 | |
| 88 | if (store.defaultExpandAll) { |
| 89 | this.expanded = true; |
| 90 | } |
| 91 | } else if (this.level > 0 && store.lazy && store.defaultExpandAll) { |
| 92 | this.expand(); |
| 93 | } |
| 94 | |
| 95 | if (!this.data) return; |
| 96 | const defaultExpandedKeys = store.defaultExpandedKeys; |
| 97 | const key = store.key; |
| 98 | if (key && defaultExpandedKeys && defaultExpandedKeys.indexOf(this.key) !== -1) { |
| 99 | this.expand(null, store.autoExpandParent); |
| 100 | } |
| 101 | |
| 102 | if (key && store.currentNodeKey && this.key === store.currentNodeKey) { |
nothing calls this directly
no test coverage detected