Skip to content

Commit 46904e7

Browse files
author
Scott J. Miles
committed
Normalize inheritance systems, standardize chainObject, and implement a version for IE
1 parent 4945dbf commit 46904e7

File tree

3 files changed

+45
-31
lines changed

3 files changed

+45
-31
lines changed

src/declaration/attributes.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,18 @@
55
*/
66
(function(scope) {
77

8-
// imports
9-
108
// magic words
119

1210
var ATTRIBUTES_ATTRIBUTE = 'attributes';
1311

1412
// attributes api
1513

16-
if (Object.__proto__) {
17-
var chainObject = function(object, inherited) {
18-
if (inherited && object !== inherited) {
19-
object.__proto__ = inherited;
20-
}
21-
}
22-
} else {
23-
chainObject = function(object, inherited) {
24-
throw "Fix chainObject for IE";
25-
}
26-
}
27-
2814
var attributes = {
2915
inheritAttributesObjects: function(prototype) {
30-
// chain our LC property map to our inherited version
31-
chainObject(prototype._publishLC, prototype.__proto__._publishLC);
32-
prototype._instanceAttributes = {};
33-
chainObject(prototype._instanceAttributes, prototype.__proto__._instanceAttributes);
16+
// chain our lower-cased publish map to the inherited version
17+
this.inheritObject(prototype, 'publishLC');
18+
// chain our instance attributes map to the inherited version
19+
this.inheritObject(prototype, '_instanceAttributes');
3420
},
3521
publishAttributes: function(prototype, base) {
3622
// merge names from 'attributes' attribute

src/declaration/prototype.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,31 @@
6363
this.publishProperties(prototype, base);
6464
// infer observers for `observe` list based on method names
6565
this.inferObservers(prototype);
66-
// chain observe object
67-
chainObject(prototype.observe, base.observe);
68-
// chain publish object
69-
chainObject(prototype.publish, base.publish);
66+
// chain various meta-data objects to inherited versions
67+
this.inheritMetaData(prototype, base);
68+
// chain custom api to inherited
69+
prototype = this.chainObject(prototype, base);
7070
// build side-chained lists to optimize iterations
7171
this.optimizePropertyMaps(prototype, base);
72-
// chain custom api
73-
chainObject(prototype, base);
7472
// inherit publishing meta-data
75-
this.inheritAttributesObjects(prototype);
76-
this.inheritDelegates(prototype);
73+
//this.inheritAttributesObjects(prototype);
74+
//this.inheritDelegates(prototype);
7775
// x-platform fixups
7876
ensurePrototypeTraversal(prototype);
7977
return prototype;
8078
},
79+
inheritMetaData: function(prototype, base) {
80+
// chain observe object to inherited
81+
this.inheritObject('observe', prototype, base);
82+
// chain publish object to inherited
83+
this.inheritObject('publish', prototype, base);
84+
// chain our lower-cased publish map to the inherited version
85+
this.inheritObject('_publishLC', prototype, base);
86+
// chain our instance attributes map to the inherited version
87+
this.inheritObject('_instanceAttributes', prototype, base);
88+
// chain our event delegates map to the inherited version
89+
this.inheritObject('eventDelegates', prototype, base);
90+
},
8191
// implement various declarative features
8292
desugar: function(prototype) {
8393
// compile list of attributes to copy to instances
@@ -129,10 +139,12 @@
129139
// return buffed-up prototype
130140
return prototype;
131141
},
132-
// make a fresh object that inherits from a prototype object
133-
inheritObject: function(prototype, name) {
134-
// copy inherited properties onto a new object
135-
prototype[name] = extend({}, Object.getPrototypeOf(prototype)[name]);
142+
// ensure prototype[name] inherits from a prototype.prototype[name]
143+
inheritObject: function(name, prototype, base) {
144+
// require an object
145+
var source = prototype[name] || {};
146+
// chain inherited properties onto a new object
147+
prototype[name] = this.chainObject(source, base[name]);
136148
},
137149
// register 'prototype' to custom element 'name', store constructor
138150
registerPrototype: function(name) {
@@ -147,6 +159,23 @@
147159
}
148160
};
149161

162+
if (Object.__proto__) {
163+
prototype.chainObject = function(object, inherited) {
164+
if (object && inherited && object !== inherited) {
165+
object.__proto__ = inherited;
166+
}
167+
return object;
168+
}
169+
} else {
170+
prototype.chainObject = function(object, inherited) {
171+
if (object && inherited && object !== inherited) {
172+
var chained = Object.create(inherited);
173+
object = extend(chained, object);
174+
}
175+
return object;
176+
}
177+
}
178+
150179
// memoize base prototypes
151180
memoizedBases = {};
152181

src/instance/properties.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// magic words
1313

1414
var OBSERVE_SUFFIX = 'Changed';
15-
//var PUBLISHED = scope.api.instance.attributes.PUBLISHED;
1615

1716
// element api
1817

0 commit comments

Comments
 (0)