Commit 39857909 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Polymer 3: Restore Templatizer to polymer.js

This was removed in https://crrev.com/c/1790641 since there is no more
chromium code that uses Templatizer directly. However, Templatizer is
still used by iron-list, so this needs to be restored in order to
compile pages that use iron-list (e.g. chrome://extensions).

This causes a 438 byte increase in size in polymer_bundled.min.js
(from 147272 to 147710).

Bug: 1004967
Change-Id: I51235bde1daf3155f0951f85d4ae4111af9d7bd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832629
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701408}
parent b8e3fc35
...@@ -12912,6 +12912,126 @@ Code distributed by Google as part of the polymer project is also ...@@ -12912,6 +12912,126 @@ Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/ */
/**
* The `Templatizer` behavior adds methods to generate instances of
* templates that are each managed by an anonymous `PropertyEffects`
* instance where data-bindings in the stamped template content are bound to
* accessors on itself.
*
* This behavior is provided in Polymer 2.x-3.x as a hybrid-element convenience
* only. For non-hybrid usage, the `Templatize` library
* should be used instead.
*
* Example:
*
* import {dom} from '@polymer/polymer/polymer_bundled.min.js';
* // Get a template from somewhere, e.g. light DOM
* let template = this.querySelector('template');
* // Prepare the template
* this.templatize(template);
* // Instance the template with an initial data model
* let instance = this.stamp({myProp: 'initial'});
* // Insert the instance's DOM somewhere, e.g. light DOM
* dom(this).appendChild(instance.root);
* // Changing a property on the instance will propagate to bindings
* // in the template
* instance.myProp = 'new value';
*
* Users of `Templatizer` may need to implement the following abstract
* API's to determine how properties and paths from the host should be
* forwarded into to instances:
*
* _forwardHostPropV2: function(prop, value)
*
* Likewise, users may implement these additional abstract API's to determine
* how instance-specific properties that change on the instance should be
* forwarded out to the host, if necessary.
*
* _notifyInstancePropV2: function(inst, prop, value)
*
* In order to determine which properties are instance-specific and require
* custom notification via `_notifyInstanceProp`, define an `_instanceProps`
* object containing keys for each instance prop, for example:
*
* _instanceProps: {
* item: true,
* index: true
* }
*
* Any properties used in the template that are not defined in _instanceProp
* will be forwarded out to the Templatize `owner` automatically.
*
* Users may also implement the following abstract function to show or
* hide any DOM generated using `stamp`:
*
* _showHideChildren: function(shouldHide)
*
* Note that some callbacks are suffixed with `V2` in the Polymer 2.x behavior
* as the implementations will need to differ from the callbacks required
* by the 1.x Templatizer API due to changes in the `TemplateInstance` API
* between versions 1.x and 2.x.
*
* @polymerBehavior
*/
const Templatizer = {
/**
* Generates an anonymous `TemplateInstance` class (stored as `this.ctor`)
* for the provided template. This method should be called once per
* template to prepare an element for stamping the template, followed
* by `stamp` to create new instances of the template.
*
* @param {!HTMLTemplateElement} template Template to prepare
* @param {boolean=} mutableData When `true`, the generated class will skip
* strict dirty-checking for objects and arrays (always consider them to
* be "dirty"). Defaults to false.
* @return {void}
* @this {TemplatizerUser}
*/
templatize(template, mutableData) {
this._templatizerTemplate = template;
this.ctor = templatize(template, this, {
mutableData: Boolean(mutableData),
parentModel: this._parentModel,
instanceProps: this._instanceProps,
forwardHostProp: this._forwardHostPropV2,
notifyInstanceProp: this._notifyInstancePropV2
});
},
/**
* Creates an instance of the template prepared by `templatize`. The object
* returned is an instance of the anonymous class generated by `templatize`
* whose `root` property is a document fragment containing newly cloned
* template content, and which has property accessors corresponding to
* properties referenced in template bindings.
*
* @param {Object=} model Object containing initial property values to
* populate into the template bindings.
* @return {TemplateInstanceBase} Returns the created instance of
* the template prepared by `templatize`.
* @this {TemplatizerUser}
*/
stamp(model) {
return new this.ctor(model);
},
/**
* Returns the template "model" (`TemplateInstance`) associated with
* a given element, which serves as the binding scope for the template
* instance the element is contained in. A template model should be used
* to manipulate data associated with this template instance.
*
* @param {HTMLElement} el Element for which to return a template model.
* @return {TemplateInstanceBase} Model representing the binding scope for
* the element.
* @this {TemplatizerUser}
*/
modelForElement(el) {
return modelForElement(this._templatizerTemplate, el);
}
};
/** /**
@license @license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved. Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
...@@ -14902,4 +15022,4 @@ Code distributed by Google as part of the polymer project is also ...@@ -14902,4 +15022,4 @@ Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/ */
export { Base, Debouncer, OptionalMutableDataBehavior, Polymer, PolymerElement, TemplateInstanceBase, afterNextRender, animationFrame, beforeNextRender, dashToCamelCase, dom, enqueueDebouncer, flush, gestures$1 as gestures, html, idlePeriod, matches, microTask, templatize, translate, useShadow }; export { Base, Debouncer, OptionalMutableDataBehavior, Polymer, PolymerElement, TemplateInstanceBase, Templatizer, afterNextRender, animationFrame, beforeNextRender, dashToCamelCase, dom, enqueueDebouncer, flush, gestures$1 as gestures, html, idlePeriod, matches, microTask, templatize, translate, useShadow };
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -22,4 +22,5 @@ export {OptionalMutableDataBehavior} from './lib/legacy/mutable-data-behavior.js ...@@ -22,4 +22,5 @@ export {OptionalMutableDataBehavior} from './lib/legacy/mutable-data-behavior.js
export {Polymer} from './lib/legacy/polymer-fn.js'; export {Polymer} from './lib/legacy/polymer-fn.js';
export {PolymerElement} from './polymer-element.js'; export {PolymerElement} from './polymer-element.js';
export {TemplateInstanceBase, templatize} from './lib/utils/templatize.js'; export {TemplateInstanceBase, templatize} from './lib/utils/templatize.js';
export {Templatizer} from './lib/legacy/templatizer-behavior.js';
export {useShadow} from './lib/utils/settings.js'; export {useShadow} from './lib/utils/settings.js';
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment