Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit dee245c

Browse files
author
Scott J. Miles
committed
Simplify publishAttributes, use undefined instead of nob to register a property with no default value
1 parent 80c8e1e commit dee245c

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/declaration/attributes.js

+12-20
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,27 @@
2525
},
2626

2727
publishAttributes: function(prototype, base) {
28-
// merge names from 'attributes' attribute
28+
// merge names from 'attributes' attribute into the 'publish' object
2929
var attributes = this.getAttribute(ATTRIBUTES_ATTRIBUTE);
3030
if (attributes) {
31-
// get properties to publish
32-
var publish = prototype.publish || (prototype.publish = {});
31+
// create a `publish` object if needed.
32+
// the `publish` object is only relevant to this prototype, the
33+
// publishing logic in `declaration/properties.js` is responsible for
34+
// managing property values on the prototype chain.
35+
// TODO(sjmiles): the `publish` object is later chained to it's
36+
// ancestor object, presumably this is only for
37+
// reflection or other non-library uses.
38+
var publish = prototype.publish || (prototype.publish = {});
3339
// names='a b c' or names='a,b,c'
3440
var names = attributes.split(ATTRIBUTES_REGEX);
3541
// record each name for publishing
3642
for (var i=0, l=names.length, n; i<l; i++) {
3743
// remove excess ws
3844
n = names[i].trim();
39-
// if the user hasn't specified a value, we want to use the
40-
// default, unless a superclass has already chosen one
45+
// looks weird, but causes n to exist on `publish` if it does not;
46+
// a more careful test would need expensive `in` operator
4147
if (n && publish[n] === undefined) {
42-
// TODO(sjmiles): querying native properties on IE11 (and possibly
43-
// on other browsers) throws an exception because there is no actual
44-
// instance.
45-
// In fact, trying to publish native properties is known bad for this
46-
// and other reasons, and we need to solve this problem writ large.
47-
try {
48-
var hasValue = (base[n] !== undefined);
49-
} catch(x) {
50-
hasValue = false;
51-
}
52-
// supply an empty 'descriptor' object and let the publishProperties
53-
// code determine a default
54-
if (!hasValue) {
55-
publish[n] = Polymer.nob;
56-
}
48+
publish[n] = undefined;
5749
}
5850
}
5951
}

0 commit comments

Comments
 (0)