| 68 | } |
| 69 | |
| 70 | public createModule() { |
| 71 | const self = this; |
| 72 | return { |
| 73 | create(oldVNode: VNode, vNode: VNode) { |
| 74 | const {data: oldData = {}} = oldVNode; |
| 75 | const {elm, data = {}} = vNode; |
| 76 | const oldFullScope: string = (oldData as any).isolate || ''; |
| 77 | const fullScope: string = (data as any).isolate || ''; |
| 78 | |
| 79 | // Update data structures with the newly-created element |
| 80 | if (fullScope) { |
| 81 | self.fullScopesBeingUpdated.push(fullScope); |
| 82 | if (oldFullScope) { self.elementsByFullScope.delete(oldFullScope); } |
| 83 | self.elementsByFullScope.set(fullScope, elm as Element); |
| 84 | |
| 85 | // Update delegators for this scope |
| 86 | const delegators = self.delegatorsByFullScope.get(fullScope); |
| 87 | if (delegators) { |
| 88 | const len = delegators.length; |
| 89 | for (let i = 0; i < len; ++i) { |
| 90 | delegators[i].updateOrigin(elm as Element); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | if (oldFullScope && !fullScope) { |
| 95 | self.elementsByFullScope.delete(fullScope); |
| 96 | } |
| 97 | }, |
| 98 | |
| 99 | update(oldVNode: VNode, vNode: VNode) { |
| 100 | const {data: oldData = {}} = oldVNode; |
| 101 | const {elm, data = {}} = vNode; |
| 102 | const oldFullScope: string = (oldData as any).isolate || ''; |
| 103 | const fullScope: string = (data as any).isolate || ''; |
| 104 | |
| 105 | // Same element, but different scope, so update the data structures |
| 106 | if (fullScope && fullScope !== oldFullScope) { |
| 107 | if (oldFullScope) { self.elementsByFullScope.delete(oldFullScope); } |
| 108 | self.elementsByFullScope.set(fullScope, elm as Element); |
| 109 | const delegators = self.delegatorsByFullScope.get(oldFullScope); |
| 110 | if (delegators) { |
| 111 | self.delegatorsByFullScope.delete(oldFullScope); |
| 112 | self.delegatorsByFullScope.set(fullScope, delegators); |
| 113 | } |
| 114 | } |
| 115 | // Same element, but lost the scope, so update the data structures |
| 116 | if (oldFullScope && !fullScope) { |
| 117 | self.elementsByFullScope.delete(oldFullScope); |
| 118 | self.delegatorsByFullScope.delete(oldFullScope); |
| 119 | } |
| 120 | }, |
| 121 | |
| 122 | destroy(vNode: VNode) { |
| 123 | self.cleanupVNode(vNode); |
| 124 | }, |
| 125 | |
| 126 | remove(vNode: VNode, cb: Function) { |
| 127 | self.cleanupVNode(vNode); |