* An updateable instance of a Template. Holds references to the Parts used to * update the template instance.
| 1185 | * update the template instance. |
| 1186 | */ |
| 1187 | class TemplateInstance implements Disconnectable { |
| 1188 | _$template: Template; |
| 1189 | _$parts: Array<Part | undefined> = []; |
| 1190 | |
| 1191 | /** @internal */ |
| 1192 | _$parent: ChildPart; |
| 1193 | /** @internal */ |
| 1194 | _$disconnectableChildren?: Set<Disconnectable> = undefined; |
| 1195 | |
| 1196 | constructor(template: Template, parent: ChildPart) { |
| 1197 | this._$template = template; |
| 1198 | this._$parent = parent; |
| 1199 | } |
| 1200 | |
| 1201 | // Called by ChildPart parentNode getter |
| 1202 | get parentNode() { |
| 1203 | return this._$parent.parentNode; |
| 1204 | } |
| 1205 | |
| 1206 | // See comment in Disconnectable interface for why this is a getter |
| 1207 | get _$isConnected() { |
| 1208 | return this._$parent._$isConnected; |
| 1209 | } |
| 1210 | |
| 1211 | // This method is separate from the constructor because we need to return a |
| 1212 | // DocumentFragment and we don't want to hold onto it with an instance field. |
| 1213 | _clone(options: RenderOptions | undefined) { |
| 1214 | const { |
| 1215 | el: {content}, |
| 1216 | parts: parts, |
| 1217 | } = this._$template; |
| 1218 | const fragment = (options?.creationScope ?? d).importNode(content, true); |
| 1219 | walker.currentNode = fragment; |
| 1220 | |
| 1221 | let node = walker.nextNode()!; |
| 1222 | let nodeIndex = 0; |
| 1223 | let partIndex = 0; |
| 1224 | let templatePart = parts[0]; |
| 1225 | |
| 1226 | while (templatePart !== undefined) { |
| 1227 | if (nodeIndex === templatePart.index) { |
| 1228 | let part: Part | undefined; |
| 1229 | if (templatePart.type === CHILD_PART) { |
| 1230 | part = new ChildPart( |
| 1231 | node as HTMLElement, |
| 1232 | node.nextSibling, |
| 1233 | this, |
| 1234 | options |
| 1235 | ); |
| 1236 | } else if (templatePart.type === ATTRIBUTE_PART) { |
| 1237 | part = new templatePart.ctor( |
| 1238 | node as HTMLElement, |
| 1239 | templatePart.name, |
| 1240 | templatePart.strings, |
| 1241 | this, |
| 1242 | options |
| 1243 | ); |
| 1244 | } else if (templatePart.type === ELEMENT_PART) { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…