mirror of
https://github.com/Polymer/polymer.git
synced 2026-08-19 01:14:44 -05:00
Avoid copying certain properties from behaviors
This better matches what Polymer 1.x did for: * hostAttributes * listeners * properties * observers
This commit is contained in:
+25
-14
@@ -14,7 +14,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
|
||||
'use strict';
|
||||
|
||||
const metaProps = {
|
||||
const lifecycleProps = {
|
||||
attached: true,
|
||||
detached: true,
|
||||
ready: true,
|
||||
@@ -22,18 +22,29 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
beforeRegister: true,
|
||||
registered: true,
|
||||
attributeChanged: true,
|
||||
};
|
||||
|
||||
const excludeProps = Object.assign({
|
||||
behaviors: true
|
||||
}, metaProps);
|
||||
|
||||
const lifecycleProps = Object.assign({
|
||||
listeners: true,
|
||||
hostAttributes: true
|
||||
}, metaProps);
|
||||
};
|
||||
|
||||
function copyProperties(source, target) {
|
||||
const excludeOnInfo = {
|
||||
attached: true,
|
||||
detached: true,
|
||||
ready: true,
|
||||
created: true,
|
||||
beforeRegister: true,
|
||||
registered: true,
|
||||
attributeChanged: true,
|
||||
behaviors: true
|
||||
};
|
||||
|
||||
const excludeOnBehaviors = Object.assign({
|
||||
listeners: true,
|
||||
hostAttributes: true,
|
||||
properties: true,
|
||||
observers: true,
|
||||
}, excludeOnInfo);
|
||||
|
||||
function copyProperties(source, target, excludeProps) {
|
||||
for (let p in source) {
|
||||
// NOTE: cannot copy `excludeProps` methods onto prototype at least because
|
||||
// `super.ready` must be called and is not included in the user fn.
|
||||
@@ -97,12 +108,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
// (again same as 1.x)
|
||||
function applyBehaviors(proto, behaviors, lifecycle) {
|
||||
for (let i=0; i<behaviors.length; i++) {
|
||||
applyInfo(proto, behaviors[i], lifecycle);
|
||||
applyInfo(proto, behaviors[i], lifecycle, excludeOnBehaviors);
|
||||
}
|
||||
}
|
||||
|
||||
function applyInfo(proto, info, lifecycle) {
|
||||
copyProperties(info, proto);
|
||||
function applyInfo(proto, info, lifecycle, excludeProps) {
|
||||
copyProperties(info, proto, excludeProps);
|
||||
for (let p in lifecycleProps) {
|
||||
if (info[p]) {
|
||||
lifecycle[p] = lifecycle[p] || [];
|
||||
@@ -282,7 +293,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
if (behaviorList) {
|
||||
applyBehaviors(proto, behaviorList, lifecycle);
|
||||
}
|
||||
applyInfo(proto, info, lifecycle);
|
||||
applyInfo(proto, info, lifecycle, excludeOnInfo);
|
||||
let list = lifecycle.beforeRegister;
|
||||
if (list) {
|
||||
for (let i=0; i < list.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user