|
193 | 193 | return templateHost && templateHost._methodHost || templateHost; |
194 | 194 | } |
195 | 195 |
|
196 | | - function createTemplatizerClass(template, options) { |
| 196 | + function createTemplatizerClass(template, templateInfo, options) { |
197 | 197 | // Anonymous class created by the templatize |
198 | 198 | /** |
199 | 199 | * @unrestricted |
|
203 | 203 | let klass = class extends base { } |
204 | 204 | klass.prototype.__templatizeOptions = options; |
205 | 205 | klass.prototype._bindTemplate(template); |
206 | | - addNotifyEffects(klass, template, options); |
| 206 | + addNotifyEffects(klass, template, templateInfo, options); |
207 | 207 | return klass; |
208 | 208 | } |
209 | 209 |
|
210 | | - function addPropagateEffects(template, options) { |
211 | | - let templateInfo = template._templateInfo; |
| 210 | + function addPropagateEffects(template, templateInfo, options) { |
212 | 211 | let userForwardHostProp = options.forwardHostProp; |
213 | 212 | if (userForwardHostProp) { |
214 | 213 | // Provide data API and property effects on memoized template class |
|
250 | 249 | } |
251 | 250 | } |
252 | 251 |
|
253 | | - function addNotifyEffects(klass, template, options) { |
254 | | - let templateInfo = template._templateInfo; |
| 252 | + function addNotifyEffects(klass, template, templateInfo, options) { |
255 | 253 | let hostProps = templateInfo.hostProps || {}; |
256 | 254 | for (let iprop in options.instanceProps) { |
257 | 255 | delete hostProps[iprop]; |
|
381 | 379 | * @param {HTMLTemplateElement} template Template to templatize |
382 | 380 | * @param {*} owner Owner of the template instances; any optional callbacks |
383 | 381 | * will be bound to this owner. |
384 | | - * @param {*} options Options dictionary (see summary for details) |
| 382 | + * @param {*=} options Options dictionary (see summary for details) |
385 | 383 | * @return {TemplateInstanceBase} Generated class bound to the template |
386 | 384 | * provided |
387 | 385 | */ |
388 | 386 | templatize(template, owner, options) { |
| 387 | + options = options || {}; |
389 | 388 | if (template.__templatizeOwner) { |
390 | 389 | throw new Error('A <template> can only be templatized once'); |
391 | 390 | } |
392 | 391 | template.__templatizeOwner = owner; |
393 | | - let templateInfo = template._templateInfo; |
| 392 | + let templateInfo = owner.constructor._parseTemplate(template); |
394 | 393 | // Get memoized base class for the prototypical template, which |
395 | 394 | // includes property effects for binding template & forwarding |
396 | | - let baseClass = templateInfo && templateInfo.templatizeInstanceClass; |
| 395 | + let baseClass = templateInfo.templatizeInstanceClass; |
397 | 396 | if (!baseClass) { |
398 | | - baseClass = createTemplatizerClass(template, options); |
399 | | - templateInfo = template._templateInfo; |
| 397 | + baseClass = createTemplatizerClass(template, templateInfo, options); |
400 | 398 | templateInfo.templatizeInstanceClass = baseClass; |
401 | 399 | } |
402 | 400 | // Host property forwarding must be installed onto template instance |
403 | | - addPropagateEffects(template, options); |
| 401 | + addPropagateEffects(template, templateInfo, options); |
404 | 402 | // Subclass base class and add reference for this specific template |
405 | 403 | let klass = class TemplateInstance extends baseClass {}; |
406 | 404 | klass.prototype._methodHost = findMethodHost(template); |
|
0 commit comments