* Replaces a child vnode inside a vnode tree by a given id * @param {Object} vnode * @param {String} id * @param {Object} newChildVnode * @returns {Boolean} true in case the node was found and replaced
(vnode, id, newChildVnode)
| 260 | * @returns {Boolean} true in case the node was found and replaced |
| 261 | */ |
| 262 | static replaceChildVnode(vnode, id, newChildVnode) { |
| 263 | vnode = VNode.getVnode(vnode); |
| 264 | |
| 265 | let childNodes = vnode.childNodes || [], |
| 266 | i = 0, |
| 267 | len = childNodes.length, |
| 268 | childNode; |
| 269 | |
| 270 | if (vnode.id === id) { |
| 271 | throw new Error('replaceChildVnode: target id matches the root vnode id: ' + id) |
| 272 | } |
| 273 | |
| 274 | for (; i < len; i++) { |
| 275 | childNode = VNode.getVnode(childNodes[i]); |
| 276 | |
| 277 | if (childNode.id === id) { |
| 278 | childNodes[i] = newChildVnode; |
| 279 | return true |
| 280 | } |
| 281 | |
| 282 | if (VNode.replaceChildVnode(childNode, id, newChildVnode)) { |
| 283 | return true |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | return false |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | export default Neo.setupClass(VNode); |