html-element-property-mixins
Advanced tools
Comparing version 0.10.9 to 0.10.10
{ | ||
"name": "html-element-property-mixins", | ||
"version": "0.10.9", | ||
"version": "0.10.10", | ||
"description": "A collection of mixins extending HTMLElement with properties.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
export const DOMProperties = (SuperClass) => class extends SuperClass { | ||
constructor() { | ||
super(); | ||
this.constructor.__saveInitialAttributeValues.call(this); | ||
} | ||
connectedCallback() { | ||
super.connectedCallback && super.connectedCallback(); | ||
this.constructor.__setInitialAttributeValues.call(this); | ||
} | ||
static get observedAttributes() { | ||
@@ -27,16 +17,2 @@ const observedAttributes = []; | ||
static __saveInitialAttributeValues() { | ||
const attrValues = new Map(); | ||
const attributes = Array.from(this.attributes); | ||
for(var i in attributes) attrValues.set(attributes[i], this.getAttribute(attributes[i])) | ||
this.__initialAttributeValues = attrValues; | ||
} | ||
static __setInitialAttributeValues() { | ||
const attrValues = this.__initialAttributeValues; | ||
attrValues.forEach((val, attrName) => { | ||
if(val !== null) this.setAttribute(attrName, val) | ||
}) | ||
} | ||
static __getPropertyNameByAttributeName(attrName) { | ||
@@ -43,0 +19,0 @@ const attributeNames = this.constructor.propertyAttributeNames; |
@@ -10,3 +10,2 @@ export const ObservedProperties = (SuperClass) => class extends SuperClass { | ||
connectedCallback() { | ||
this.constructor.__propertiesInited = true; | ||
super.connectedCallback && super.connectedCallback(); | ||
@@ -13,0 +12,0 @@ this.constructor.__setInitialPropertyValues.call(this); |
export const ReflectedProperties = (SuperClass) => class extends SuperClass { | ||
connectedCallback() { | ||
super.connectedCallback(); | ||
for(var i in this.constructor.reflectedProperties) { | ||
const propName = this.constructor.reflectedProperties[i]; | ||
const attrName = this.constructor.__getAttributeNameByPropertyName.call(this, propName); | ||
this.constructor.__setDOMAttribute.call(this, attrName, propName, this[propName]); | ||
} | ||
} | ||
propertyChangedCallback(propName, oldValue, newValue) { | ||
super.propertyChangedCallback && super.propertyChangedCallback(propName, oldValue, newValue); | ||
if(!this.isConnected) return; | ||
const reflectedProps = this.constructor.reflectedProperties || {}; | ||
const attrReflects = reflectedProps.indexOf(propName) !== -1; | ||
if(!attrReflects) return; | ||
const attrName = this.constructor.__getAttributeNameByPropertyName.call(this, propName); | ||
if(!this.isConnected) return; | ||
if(!this.constructor.__propertiesInited) return; | ||
this.constructor.__setDOMAttribute.call(this, attrName, propName, newValue); | ||
@@ -23,3 +33,3 @@ } | ||
static __getAttributeNameByPropertyName(propName) { | ||
const reflectedProps = this.constructor.reflectedProperties || {}; | ||
const reflectedProps = this.constructor.reflectedProperties || []; | ||
const attrNames = this.constructor.propertyAttributeNames || {}; | ||
@@ -26,0 +36,0 @@ if(reflectedProps.indexOf(propName) === -1) return; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38119
244