-
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.
Provides minimal element starting point using PropertyAccessors to create properties using a properties object similar to Polymer.Element. No template or binding support is provided.
- Loading branch information
Steven Orvell
committed
Sep 15, 2017
1 parent
aa4f186
commit 717a4f4
Showing
3 changed files
with
482 additions
and
2 deletions.
There are no files selected for viewing
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,100 @@ | ||
<!-- | ||
@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/property-accessors.html"> | ||
|
||
<script> | ||
(function() { | ||
'use strict'; | ||
|
||
/** | ||
* Custom element base class that provides minimal starting point | ||
* using PropertyAccessors to create properties. | ||
* | ||
* @customElement | ||
* @polymer | ||
* @memberof Polymer | ||
* @constructor | ||
* @implements {Polymer_PropertyAccessors} | ||
* @extends HTMLElement | ||
* @appliesMixin Polymer.PropertyAccessors | ||
* @summary Custom element base class that provides minimal starting point | ||
* using PropertyAccessors to create properties | ||
*/ | ||
class BasicElement extends Polymer.PropertyAccessors(HTMLElement) { | ||
|
||
static _ensureFinalized(name) { | ||
const proto = this.prototype; | ||
if (!proto.hasOwnProperty('__finalized')) { | ||
proto.__finalized = true; | ||
this.finalize(name); | ||
} | ||
} | ||
|
||
static get observedAttributes() { | ||
const props = this.properties; | ||
return props ? Object.keys(props) : []; | ||
} | ||
|
||
/** | ||
* 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) { | ||
const props = this.properties; | ||
if (props) { | ||
this.prototype.__propertyInfo = props; | ||
this.createProperties(Object.keys(props)); | ||
} | ||
} | ||
|
||
/** | ||
* Overrides default behavior and adds a call to `finalize`. | ||
* @override | ||
*/ | ||
_initializeProperties() { | ||
this.constructor._ensureFinalized(this.localName); | ||
super._initializeProperties(); | ||
} | ||
|
||
_attributeToProperty(attribute, value, type) { | ||
if (!type) { | ||
const property = this._propertyNameForAttribute(attribute); | ||
const props = this.__propertyInfo; | ||
const info = props && props[property]; | ||
type = info && info.type || info ; | ||
} | ||
super._attributeToProperty(attribute, value, type); | ||
} | ||
|
||
connectedCallback() { | ||
this._enableProperties(); | ||
} | ||
|
||
/** | ||
* Called when the element is removed from a document | ||
*/ | ||
disconnectedCallback() {} | ||
|
||
} | ||
/** | ||
* @constructor | ||
* @implements {Polymer_PropertyAccessors} | ||
* @extends {HTMLElement} | ||
*/ | ||
Polymer.BasicElement = BasicElement; | ||
|
||
})(); | ||
|
||
</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
Oops, something went wrong.