(node, ref)
| 842 | } |
| 843 | |
| 844 | insertBefore(node, ref) { |
| 845 | if (!(node instanceof Node)) return |
| 846 | if (ref && !(ref instanceof Node)) return |
| 847 | |
| 848 | let nodes |
| 849 | let hasUpdate = false |
| 850 | |
| 851 | if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { |
| 852 | // documentFragment |
| 853 | nodes = [] |
| 854 | for (let i = 0; i < node.childNodes.length; i++) { |
| 855 | // 因为是逐个插入,所以需要逆序 |
| 856 | nodes.push(node.childNodes[i]) |
| 857 | } |
| 858 | } else { |
| 859 | nodes = [node] |
| 860 | } |
| 861 | |
| 862 | for (const node of nodes) { |
| 863 | if (node === this) continue |
| 864 | if (node.parentNode) node.parentNode.removeChild(node) |
| 865 | |
| 866 | const insertIndex = ref ? this.$_children.indexOf(ref) : -1 |
| 867 | |
| 868 | if (insertIndex === -1) { |
| 869 | // 插入到末尾 |
| 870 | this.$_children.push(node) |
| 871 | } else { |
| 872 | // 插入到 ref 之前 |
| 873 | this.$_children.splice(insertIndex, 0, node) |
| 874 | } |
| 875 | |
| 876 | node.$$updateParent(this) // 设置 parentNode |
| 877 | |
| 878 | // 更新映射表 |
| 879 | this.$_updateChildrenExtra(node) |
| 880 | |
| 881 | hasUpdate = true |
| 882 | } |
| 883 | |
| 884 | |
| 885 | // 触发 webview 端更新 |
| 886 | if (hasUpdate) this.$_triggerMeUpdate() |
| 887 | |
| 888 | return node |
| 889 | } |
| 890 | |
| 891 | replaceChild(node, old) { |
| 892 | if (!(node instanceof Node) || !(old instanceof Node)) return |
no test coverage detected