UNPKG

es5-lit-element

Version:
890 lines (746 loc) 33.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UpdatingElement = exports.notEqual = exports.defaultConverter = void 0; function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * 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 */ var _a; /** * When using Closure Compiler, JSCompiler_renameProperty(property, object) is * replaced at compile time by the munged name for object[property]. We cannot * alias this function, so we have to use a small shim that has the same * behavior when not compiling. */ window.JSCompiler_renameProperty = function (prop, _obj) { return prop; }; var defaultConverter = { toAttribute: function toAttribute(value, type) { switch (type) { case Boolean: return value ? '' : null; case Object: case Array: // if the value is `null` or `undefined` pass this through // to allow removing/no change behavior. return value == null ? value : JSON.stringify(value); } return value; }, fromAttribute: function fromAttribute(value, type) { switch (type) { case Boolean: return value !== null; case Number: return value === null ? null : Number(value); case Object: case Array: return JSON.parse(value); } return value; } }; /** * Change function that returns true if `value` is different from `oldValue`. * This method is used as the default for a property's `hasChanged` function. */ exports.defaultConverter = defaultConverter; var notEqual = function notEqual(value, old) { // This ensures (old==NaN, value==NaN) always returns false return old !== value && (old === old || value === value); }; exports.notEqual = notEqual; var defaultPropertyDeclaration = { attribute: true, type: String, converter: defaultConverter, reflect: false, hasChanged: notEqual }; var microtaskPromise = Promise.resolve(true); var STATE_HAS_UPDATED = 1; var STATE_UPDATE_REQUESTED = 1 << 2; var STATE_IS_REFLECTING_TO_ATTRIBUTE = 1 << 3; var STATE_IS_REFLECTING_TO_PROPERTY = 1 << 4; var STATE_HAS_CONNECTED = 1 << 5; /** * The Closure JS Compiler doesn't currently have good support for static * property semantics where "this" is dynamic (e.g. * https://github.com/google/closure-compiler/issues/3177 and others) so we use * this hack to bypass any rewriting by the compiler. */ var finalized = 'finalized'; /** * Base element class which manages element properties and attributes. When * properties change, the `update` method is asynchronously called. This method * should be supplied by subclassers to render updates as desired. */ var UpdatingElement = /*#__PURE__*/ function (_HTMLElement) { _inherits(UpdatingElement, _HTMLElement); function UpdatingElement() { var _this; _classCallCheck(this, UpdatingElement); _this = _possibleConstructorReturn(this, _getPrototypeOf(UpdatingElement).call(this)); _this._updateState = 0; _this._instanceProperties = undefined; _this._updatePromise = microtaskPromise; _this._hasConnectedResolver = undefined; /** * Map with keys for any properties that have changed since the last * update cycle with previous values. */ _this._changedProperties = new Map(); /** * Map with keys of properties that should be reflected when updated. */ _this._reflectingProperties = undefined; _this.initialize(); return _this; } /** * Returns a list of attributes corresponding to the registered properties. * @nocollapse */ _createClass(UpdatingElement, [{ key: "initialize", /** * Performs element initialization. By default captures any pre-set values for * registered properties. */ value: function initialize() { this._saveInstanceProperties(); // ensures first update will be caught by an early access of // `updateComplete` this._requestUpdate(); } /** * Fixes any properties set on the instance before upgrade time. * Otherwise these would shadow the accessor and break these properties. * The properties are stored in a Map which is played back after the * constructor runs. Note, on very old versions of Safari (<=9) or Chrome * (<=41), properties created for native platform properties like (`id` or * `name`) may not have default values set in the element constructor. On * these browsers native properties appear on instances and therefore their * default value will overwrite any element default (e.g. if the element sets * this.id = 'id' in the constructor, the 'id' will become '' since this is * the native platform default). */ }, { key: "_saveInstanceProperties", value: function _saveInstanceProperties() { var _this2 = this; // Use forEach so this works even if for/of loops are compiled to for loops // expecting arrays this.constructor._classProperties.forEach(function (_v, p) { if (_this2.hasOwnProperty(p)) { var value = _this2[p]; delete _this2[p]; if (!_this2._instanceProperties) { _this2._instanceProperties = new Map(); } _this2._instanceProperties.set(p, value); } }); } /** * Applies previously saved instance properties. */ }, { key: "_applyInstanceProperties", value: function _applyInstanceProperties() { var _this3 = this; // Use forEach so this works even if for/of loops are compiled to for loops // expecting arrays // tslint:disable-next-line:no-any this._instanceProperties.forEach(function (v, p) { return _this3[p] = v; }); this._instanceProperties = undefined; } }, { key: "connectedCallback", value: function connectedCallback() { this._updateState = this._updateState | STATE_HAS_CONNECTED; // Ensure first connection completes an update. Updates cannot complete // before connection and if one is pending connection the // `_hasConnectionResolver` will exist. If so, resolve it to complete the // update, otherwise requestUpdate. if (this._hasConnectedResolver) { this._hasConnectedResolver(); this._hasConnectedResolver = undefined; } } /** * Allows for `super.disconnectedCallback()` in extensions while * reserving the possibility of making non-breaking feature additions * when disconnecting at some point in the future. */ }, { key: "disconnectedCallback", value: function disconnectedCallback() {} /** * Synchronizes property values when attributes change. */ }, { key: "attributeChangedCallback", value: function attributeChangedCallback(name, old, value) { if (old !== value) { this._attributeToProperty(name, value); } } }, { key: "_propertyToAttribute", value: function _propertyToAttribute(name, value) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultPropertyDeclaration; var ctor = this.constructor; var attr = ctor._attributeNameForProperty(name, options); if (attr !== undefined) { var attrValue = ctor._propertyValueToAttribute(value, options); // an undefined value does not change the attribute. if (attrValue === undefined) { return; } // Track if the property is being reflected to avoid // setting the property again via `attributeChangedCallback`. Note: // 1. this takes advantage of the fact that the callback is synchronous. // 2. will behave incorrectly if multiple attributes are in the reaction // stack at time of calling. However, since we process attributes // in `update` this should not be possible (or an extreme corner case // that we'd like to discover). // mark state reflecting this._updateState = this._updateState | STATE_IS_REFLECTING_TO_ATTRIBUTE; if (attrValue == null) { this.removeAttribute(attr); } else { this.setAttribute(attr, attrValue); } // mark state not reflecting this._updateState = this._updateState & ~STATE_IS_REFLECTING_TO_ATTRIBUTE; } } }, { key: "_attributeToProperty", value: function _attributeToProperty(name, value) { // Use tracking info to avoid deserializing attribute value if it was // just set from a property setter. if (this._updateState & STATE_IS_REFLECTING_TO_ATTRIBUTE) { return; } var ctor = this.constructor; var propName = ctor._attributeToPropertyMap.get(name); if (propName !== undefined) { var options = ctor._classProperties.get(propName) || defaultPropertyDeclaration; // mark state reflecting this._updateState = this._updateState | STATE_IS_REFLECTING_TO_PROPERTY; this[propName] = // tslint:disable-next-line:no-any ctor._propertyValueFromAttribute(value, options); // mark state not reflecting this._updateState = this._updateState & ~STATE_IS_REFLECTING_TO_PROPERTY; } } /** * This private version of `requestUpdate` does not access or return the * `updateComplete` promise. This promise can be overridden and is therefore * not free to access. */ }, { key: "_requestUpdate", value: function _requestUpdate(name, oldValue) { var shouldRequestUpdate = true; // If we have a property key, perform property update steps. if (name !== undefined) { var ctor = this.constructor; var options = ctor._classProperties.get(name) || defaultPropertyDeclaration; if (ctor._valueHasChanged(this[name], oldValue, options.hasChanged)) { if (!this._changedProperties.has(name)) { this._changedProperties.set(name, oldValue); } // Add to reflecting properties set. // Note, it's important that every change has a chance to add the // property to `_reflectingProperties`. This ensures setting // attribute + property reflects correctly. if (options.reflect === true && !(this._updateState & STATE_IS_REFLECTING_TO_PROPERTY)) { if (this._reflectingProperties === undefined) { this._reflectingProperties = new Map(); } this._reflectingProperties.set(name, options); } } else { // Abort the request if the property should not be considered changed. shouldRequestUpdate = false; } } if (!this._hasRequestedUpdate && shouldRequestUpdate) { this._enqueueUpdate(); } } /** * Requests an update which is processed asynchronously. This should * be called when an element should update based on some state not triggered * by setting a property. In this case, pass no arguments. It should also be * called when manually implementing a property setter. In this case, pass the * property `name` and `oldValue` to ensure that any configured property * options are honored. Returns the `updateComplete` Promise which is resolved * when the update completes. * * @param name {PropertyKey} (optional) name of requesting property * @param oldValue {any} (optional) old value of requesting property * @returns {Promise} A Promise that is resolved when the update completes. */ }, { key: "requestUpdate", value: function requestUpdate(name, oldValue) { this._requestUpdate(name, oldValue); return this.updateComplete; } /** * Sets up the element to asynchronously update. */ }, { key: "_enqueueUpdate", value: function () { var _enqueueUpdate2 = _asyncToGenerator( /*#__PURE__*/ regeneratorRuntime.mark(function _callee() { var _this4 = this; var resolve, reject, previousUpdatePromise, result; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: // Mark state updating... this._updateState = this._updateState | STATE_UPDATE_REQUESTED; previousUpdatePromise = this._updatePromise; this._updatePromise = new Promise(function (res, rej) { resolve = res; reject = rej; }); _context.prev = 3; _context.next = 6; return previousUpdatePromise; case 6: _context.next = 10; break; case 8: _context.prev = 8; _context.t0 = _context["catch"](3); case 10: if (this._hasConnected) { _context.next = 13; break; } _context.next = 13; return new Promise(function (res) { return _this4._hasConnectedResolver = res; }); case 13: _context.prev = 13; result = this.performUpdate(); // If `performUpdate` returns a Promise, we await it. This is done to // enable coordinating updates with a scheduler. Note, the result is // checked to avoid delaying an additional microtask unless we need to. if (!(result != null)) { _context.next = 18; break; } _context.next = 18; return result; case 18: _context.next = 23; break; case 20: _context.prev = 20; _context.t1 = _context["catch"](13); reject(_context.t1); case 23: resolve(!this._hasRequestedUpdate); case 24: case "end": return _context.stop(); } } }, _callee, this, [[3, 8], [13, 20]]); })); function _enqueueUpdate() { return _enqueueUpdate2.apply(this, arguments); } return _enqueueUpdate; }() }, { key: "performUpdate", /** * Performs an element update. Note, if an exception is thrown during the * update, `firstUpdated` and `updated` will not be called. * * You can override this method to change the timing of updates. If this * method is overridden, `super.performUpdate()` must be called. * * For instance, to schedule updates to occur just before the next frame: * * ``` * protected async performUpdate(): Promise<unknown> { * await new Promise((resolve) => requestAnimationFrame(() => resolve())); * super.performUpdate(); * } * ``` */ value: function performUpdate() { // Mixin instance properties once, if they exist. if (this._instanceProperties) { this._applyInstanceProperties(); } var shouldUpdate = false; var changedProperties = this._changedProperties; try { shouldUpdate = this.shouldUpdate(changedProperties); if (shouldUpdate) { this.update(changedProperties); } } catch (e) { // Prevent `firstUpdated` and `updated` from running when there's an // update exception. shouldUpdate = false; throw e; } finally { // Ensure element can accept additional updates after an exception. this._markUpdated(); } if (shouldUpdate) { if (!(this._updateState & STATE_HAS_UPDATED)) { this._updateState = this._updateState | STATE_HAS_UPDATED; this.firstUpdated(changedProperties); } this.updated(changedProperties); } } }, { key: "_markUpdated", value: function _markUpdated() { this._changedProperties = new Map(); this._updateState = this._updateState & ~STATE_UPDATE_REQUESTED; } /** * Returns a Promise that resolves when the element has completed updating. * The Promise value is a boolean that is `true` if the element completed the * update without triggering another update. The Promise result is `false` if * a property was set inside `updated()`. If the Promise is rejected, an * exception was thrown during the update. * * To await additional asynchronous work, override the `_getUpdateComplete` * method. For example, it is sometimes useful to await a rendered element * before fulfilling this Promise. To do this, first await * `super._getUpdateComplete()`, then any subsequent state. * * @returns {Promise} The Promise returns a boolean that indicates if the * update resolved without triggering another update. */ }, { key: "_getUpdateComplete", /** * Override point for the `updateComplete` promise. * * It is not safe to override the `updateComplete` getter directly due to a * limitation in TypeScript which means it is not possible to call a * superclass getter (e.g. `super.updateComplete.then(...)`) when the target * language is ES5 (https://github.com/microsoft/TypeScript/issues/338). * This method should be overridden instead. For example: * * class MyElement extends LitElement { * async _getUpdateComplete() { * await super._getUpdateComplete(); * await this._myChild.updateComplete; * } * } */ value: function _getUpdateComplete() { return this._updatePromise; } /** * Controls whether or not `update` should be called when the element requests * an update. By default, this method always returns `true`, but this can be * customized to control when to update. * * * @param _changedProperties Map of changed properties with old values */ }, { key: "shouldUpdate", value: function shouldUpdate(_changedProperties) { return true; } /** * Updates the element. This method reflects property values to attributes. * It can be overridden to render and keep updated element DOM. * Setting properties inside this method will *not* trigger * another update. * * * @param _changedProperties Map of changed properties with old values */ }, { key: "update", value: function update(_changedProperties) { var _this5 = this; if (this._reflectingProperties !== undefined && this._reflectingProperties.size > 0) { // Use forEach so this works even if for/of loops are compiled to for // loops expecting arrays this._reflectingProperties.forEach(function (v, k) { return _this5._propertyToAttribute(k, _this5[k], v); }); this._reflectingProperties = undefined; } } /** * Invoked whenever the element is updated. Implement to perform * post-updating tasks via DOM APIs, for example, focusing an element. * * Setting properties inside this method will trigger the element to update * again after this update cycle completes. * * * @param _changedProperties Map of changed properties with old values */ }, { key: "updated", value: function updated(_changedProperties) {} /** * Invoked when the element is first updated. Implement to perform one time * work on the element after update. * * Setting properties inside this method will trigger the element to update * again after this update cycle completes. * * * @param _changedProperties Map of changed properties with old values */ }, { key: "firstUpdated", value: function firstUpdated(_changedProperties) {} }, { key: "_hasConnected", get: function get() { return this._updateState & STATE_HAS_CONNECTED; } }, { key: "_hasRequestedUpdate", get: function get() { return this._updateState & STATE_UPDATE_REQUESTED; } }, { key: "hasUpdated", get: function get() { return this._updateState & STATE_HAS_UPDATED; } }, { key: "updateComplete", get: function get() { return this._getUpdateComplete(); } }], [{ key: "_ensureClassProperties", /** * Ensures the private `_classProperties` property metadata is created. * In addition to `finalize` this is also called in `createProperty` to * ensure the `@property` decorator can add property metadata. */ /** @nocollapse */ value: function _ensureClassProperties() { var _this6 = this; // ensure private storage for property declarations. if (!this.hasOwnProperty(JSCompiler_renameProperty('_classProperties', this))) { this._classProperties = new Map(); // NOTE: Workaround IE11 not supporting Map constructor argument. var superProperties = Object.getPrototypeOf(this)._classProperties; if (superProperties !== undefined) { superProperties.forEach(function (v, k) { return _this6._classProperties.set(k, v); }); } } } /** * Creates a property accessor on the element prototype if one does not exist. * The property setter calls the property's `hasChanged` property option * or uses a strict identity check to determine whether or not to request * an update. * @nocollapse */ }, { key: "createProperty", value: function createProperty(name) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultPropertyDeclaration; // Note, since this can be called by the `@property` decorator which // is called before `finalize`, we ensure storage exists for property // metadata. this._ensureClassProperties(); this._classProperties.set(name, options); // Do not generate an accessor if the prototype already has one, since // it would be lost otherwise and that would never be the user's intention; // Instead, we expect users to call `requestUpdate` themselves from // user-defined accessors. Note that if the super has an accessor we will // still overwrite it if (options.noAccessor || this.prototype.hasOwnProperty(name)) { return; } var key = _typeof(name) === 'symbol' ? Symbol() : "__".concat(name); Object.defineProperty(this.prototype, name, { // tslint:disable-next-line:no-any no symbol in index get: function get() { return this[key]; }, set: function set(value) { var oldValue = this[name]; this[key] = value; this._requestUpdate(name, oldValue); }, configurable: true, enumerable: true }); } /** * Creates property accessors for registered properties and ensures * any superclasses are also finalized. * @nocollapse */ }, { key: "finalize", value: function finalize() { // finalize any superclasses var superCtor = Object.getPrototypeOf(this); if (!superCtor.hasOwnProperty(finalized)) { superCtor.finalize(); } this[finalized] = true; this._ensureClassProperties(); // initialize Map populated in observedAttributes this._attributeToPropertyMap = new Map(); // make any properties // Note, only process "own" properties since this element will inherit // any properties defined on the superClass, and finalization ensures // the entire prototype chain is finalized. if (this.hasOwnProperty(JSCompiler_renameProperty('properties', this))) { var props = this.properties; // support symbols in properties (IE11 does not support this) var propKeys = [].concat(_toConsumableArray(Object.getOwnPropertyNames(props)), _toConsumableArray(typeof Object.getOwnPropertySymbols === 'function' ? Object.getOwnPropertySymbols(props) : [])); // This for/of is ok because propKeys is an array var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = propKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var p = _step.value; // note, use of `any` is due to TypeSript lack of support for symbol in // index types // tslint:disable-next-line:no-any no symbol in index this.createProperty(p, props[p]); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator["return"] != null) { _iterator["return"](); } } finally { if (_didIteratorError) { throw _iteratorError; } } } } } /** * Returns the property name for the given attribute `name`. * @nocollapse */ }, { key: "_attributeNameForProperty", value: function _attributeNameForProperty(name, options) { var attribute = options.attribute; return attribute === false ? undefined : typeof attribute === 'string' ? attribute : typeof name === 'string' ? name.toLowerCase() : undefined; } /** * Returns true if a property should request an update. * Called when a property value is set and uses the `hasChanged` * option for the property if present or a strict identity check. * @nocollapse */ }, { key: "_valueHasChanged", value: function _valueHasChanged(value, old) { var hasChanged = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : notEqual; return hasChanged(value, old); } /** * Returns the property value for the given attribute value. * Called via the `attributeChangedCallback` and uses the property's * `converter` or `converter.fromAttribute` property option. * @nocollapse */ }, { key: "_propertyValueFromAttribute", value: function _propertyValueFromAttribute(value, options) { var type = options.type; var converter = options.converter || defaultConverter; var fromAttribute = typeof converter === 'function' ? converter : converter.fromAttribute; return fromAttribute ? fromAttribute(value, type) : value; } /** * Returns the attribute value for the given property value. If this * returns undefined, the property will *not* be reflected to an attribute. * If this returns null, the attribute will be removed, otherwise the * attribute will be set to the value. * This uses the property's `reflect` and `type.toAttribute` property options. * @nocollapse */ }, { key: "_propertyValueToAttribute", value: function _propertyValueToAttribute(value, options) { if (options.reflect === undefined) { return; } var type = options.type; var converter = options.converter; var toAttribute = converter && converter.toAttribute || defaultConverter.toAttribute; return toAttribute(value, type); } }, { key: "observedAttributes", get: function get() { var _this7 = this; // note: piggy backing on this to ensure we're finalized. this.finalize(); var attributes = []; // Use forEach so this works even if for/of loops are compiled to for loops // expecting arrays this._classProperties.forEach(function (v, p) { var attr = _this7._attributeNameForProperty(p, v); if (attr !== undefined) { _this7._attributeToPropertyMap.set(attr, p); attributes.push(attr); } }); return attributes; } }]); return UpdatingElement; }(_wrapNativeSuper(HTMLElement)); exports.UpdatingElement = UpdatingElement; _a = finalized; /** * Marks class as having finished creating properties. */ UpdatingElement[_a] = true;