-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed basic element to properties element
Exposed `PropertiesMixin` also.
- Loading branch information
Steven Orvell
committed
Sep 21, 2017
1 parent
d26955b
commit e3e128b
Showing
6 changed files
with
198 additions
and
142 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!-- | ||
@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 | ||
--> | ||
|
||
<link rel="import" href="../utils/boot.html"> | ||
<link rel="import" href="../utils/mixin.html"> | ||
<link rel="import" href="../mixins/properties-mixin.html"> | ||
|
||
<script> | ||
'use strict'; | ||
|
||
/** | ||
* Base class that provides a simple starting point for creating an element | ||
* that declares properties via the `properties` static getter that are | ||
* observed. Changes are reported via the `_propertiesChanged` method. | ||
* This element provides no specific support for rendering. Users are expected | ||
* to create a shadowRoot and put content into it and update it in whatever | ||
* way makes sense for the use case. | ||
* | ||
* @customElement | ||
* @polymer | ||
* @memberof Polymer | ||
* @constructor | ||
* @implements {Polymer_PropertiesMixin} | ||
* @extends HTMLElement | ||
* @appliesMixin Polymer.PropertiesMixin | ||
* @summary Base class that provides a simple starting point for creating an | ||
* element that declares properties via the `properties` static getter that | ||
* are observed | ||
*/ | ||
const PropertiesElement = Polymer.PropertiesMixin(HTMLElement); | ||
/** | ||
* @constructor | ||
* @implements {Polymer_PropertiesMixin} | ||
* @extends {HTMLElement} | ||
*/ | ||
Polymer.PropertiesElement = PropertiesElement; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<!-- | ||
@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 | ||
--> | ||
|
||
<link rel="import" href="../utils/boot.html"> | ||
<link rel="import" href="../utils/mixin.html"> | ||
<link rel="import" href="../mixins/properties-changed.html"> | ||
|
||
<script> | ||
(function() { | ||
'use strict'; | ||
|
||
/** | ||
* Mixin that provides minimal starting point to using the PropertiesChanged | ||
* mixin by providing a mechanism to declare properties in a static | ||
* getter (e.g. static get properties() { return { foo: String } }). Changes | ||
* are reported via the `_propertiesChanged` method. | ||
* | ||
* This mixin provides no specific support for rendering. Users are expected | ||
* to create a shadowRoot and put content into it and update it in whatever | ||
* way makes sense for the use case. | ||
* | ||
* @customElement | ||
* @polymer | ||
* @memberof Polymer | ||
* @constructor | ||
* @implements {Polymer_PropertiesChanged} | ||
* @extends HTMLElement | ||
* @appliesMixin Polymer.PropertiesChanged | ||
* @summary Mixin that provides a minimal starting point for using | ||
* the PropertiesChanged mixin by providing a declarative `properties` object. | ||
*/ | ||
Polymer.PropertiesMixin = Polymer.dedupingMixin(superClass => { | ||
|
||
/** | ||
* @constructor | ||
* @extends {superClass} | ||
* @implements {Polymer_PropertiesChanged} | ||
* @unrestricted | ||
*/ | ||
const base = Polymer.PropertiesChanged(superClass); | ||
|
||
return class PropertiesElement extends base { | ||
|
||
/** | ||
* Implements standard custom elements getter to observes the attributes | ||
* listed in `properties`. | ||
*/ | ||
static get observedAttributes() { | ||
const props = this.properties; | ||
return props ? Object.keys(props).map(p => { | ||
return this.prototype._attributeForProperty(p); | ||
}) : []; | ||
} | ||
|
||
static _ensureFinalized(name) { | ||
const proto = this.prototype; | ||
if (!proto.hasOwnProperty('__finalized')) { | ||
proto.__finalized = true; | ||
this.finalize(name); | ||
} | ||
} | ||
|
||
/** | ||
* Finalizes an element definition. This includes ensuring property | ||
* accessors exist on the element prototype and parsing the element | ||
* template. | ||
* @param {string} name Name of the element | ||
*/ | ||
static finalize(name) { // eslint-disable-line no-unused-vars | ||
const props = this.properties; | ||
if (props) { | ||
this.prototype.__propertyInfo = props; | ||
this.createProperties(Object.keys(props)); | ||
} | ||
} | ||
|
||
/** | ||
* Overrides implementation in PropertiesChanged to immediately process | ||
* any pending changes to properties and ensure that | ||
* `_propertiesChanged` is called. | ||
* | ||
* @public | ||
*/ | ||
ready() { | ||
super.ready(); | ||
this._invalidateProperties(); | ||
this._validateProperties(); | ||
} | ||
|
||
/** | ||
* Overrides default behavior and adds a call to `finalize` which lazily | ||
* configures the element's property accessors. | ||
* @override | ||
*/ | ||
_initializeProperties() { | ||
this.constructor._ensureFinalized(this.localName); | ||
super._initializeProperties(); | ||
} | ||
|
||
/** | ||
* Overrides PropertiesChanged method to return type specified in the | ||
* static `properties` object for the given property. | ||
* @param {string} name Name of property | ||
* @return {*} Type to which to deserialize attribute | ||
* | ||
* @protected | ||
*/ | ||
_typeForProperty(name) { | ||
const props = this.__propertyInfo; | ||
return props && props[name]; | ||
} | ||
|
||
/** | ||
* Called when the element is added to a document. | ||
* Calls `_enableProperties` to turn on property system from | ||
* `PropertiesChanged`. | ||
*/ | ||
connectedCallback() { | ||
this._enableProperties(); | ||
} | ||
|
||
/** | ||
* Called when the element is removed from a document | ||
*/ | ||
disconnectedCallback() {} | ||
|
||
} | ||
|
||
}); | ||
|
||
})(); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.