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

Commit 284aa7f

Browse files
committed
Merge pull request #54 from Polymer/master
8/15 master -> stable
2 parents 3e50d85 + 173bbf6 commit 284aa7f

15 files changed

Lines changed: 112 additions & 520 deletions

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The `<element>` tag provides a mechanism to encapsulate HTML, CSS, and JavaScrip
3737
// Has built-in 'window' protection.
3838
this.register({
3939
prototype: {
40-
readyCallback: function() {
40+
createdCallback: function() {
4141
this.innerHTML = section.innerHTML;
4242
},
4343
foo: function() {
@@ -69,7 +69,7 @@ As before, custom elements built this way work just like standard elements.
6969
Here's the imperative version of the previous example:
7070

7171
var XFooPrototype = Object.create(HTMLElement.prototype);
72-
XFooPrototype.readyCallback = function() {
72+
XFooPrototype.createdCallback = function() {
7373
this.textContent = "I'm an x-foo!";
7474
};
7575
XFooPrototype.foo = function() {
@@ -90,7 +90,7 @@ declare the type using the `extends` option when calling `document.register()`:
9090
Example extending `button`:
9191

9292
var XFooButtonPrototype = Object.create(HTMLButtonElement.prototype);
93-
XFooButtonPrototype.readyCallback = function() {
93+
XFooButtonPrototype.createdCallback = function() {
9494
this.textContent = "I'm an x-foo button!";
9595
};
9696

@@ -121,7 +121,7 @@ This can also be used to create an instance:
121121
xFooButton.foo(); // "foo() called"
122122

123123
Browser limitations require that we supply the constructor while you supply the `prototype`.
124-
Use the `readyCallback` to do initialization work that might otherwise be in a constructor.
124+
Use the `createdCallback` to do initialization work that might otherwise be in a constructor.
125125

126126
## Polyfill details
127127

@@ -152,12 +152,12 @@ Example:
152152

153153
The Custom Elements specification is still under discussion. The polyfill implements certain features in advance of the specification. In particular, there are several notification callback methods that are used if implemented on the element prototype.
154154

155-
* `readyCallback()` is called when a custom element is created.
156-
* `insertedCallback()` is called when a custom element is inserted into a DOM subtree.
157-
* `removedCallback()` is called when a custom element is removed from a DOM subtree.
155+
* `createdCallback()` is called when a custom element is created.
156+
* `enteredDocumentCallback()` is called when a custom element is inserted into a DOM subtree.
157+
* `leftDocumentCallback()` is called when a custom element is removed from a DOM subtree.
158158
* `attributeChangedCallback(attributeName)` is called when a custom element's attribute value has changed
159159

160-
`readyCallback` is invoked _synchronously_ with element instantiation, the other callbacks are called _asyncronously_. The asynchronous callbacks generally use the MutationObserver timing model, which means they are called before layouts, paints, or other triggered events, so the developer need not worry about flashing content or other bad things happening before the callback has a chance to react to changes.
160+
`createdCallback` is invoked _synchronously_ with element instantiation, the other callbacks are called _asyncronously_. The asynchronous callbacks generally use the MutationObserver timing model, which means they are called before layouts, paints, or other triggered events, so the developer need not worry about flashing content or other bad things happening before the callback has a chance to react to changes.
161161

162162
The `extends` option to `document.register()` (discussed above) is exclusive to this polyfill.
163163

build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"src/MutationObserver.js",
66
"src/Observer.js",
77
"src/CustomElements.js",
8-
"src/HTMLElementElement.js",
98
"src/Parser.js",
109
"src/boot.js"
1110
]

custom-elements.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ var modules = [
1414
'src/MutationObserver.js',
1515
'src/Observer.js',
1616
'src/CustomElements.js',
17-
'src/HTMLElementElement.js',
1817
'src/Parser.js',
1918
'src/boot.js'
2019
];
@@ -32,10 +31,10 @@ var script = document.querySelector('script[src*="' + thisFile + '"]');
3231
var src = script.attributes.src.value;
3332
var basePath = src.slice(0, src.indexOf(thisFile));
3433

35-
if (!window.Loader) {
34+
if (!window.PolymerLoader) {
3635
var path = basePath + 'tools/loader/loader.js';
3736
document.write('<script src="' + path + '"></script>');
3837
}
39-
document.write('<script>Loader.load("' + scopeName + '")</script>');
38+
document.write('<script>PolymerLoader.load("' + scopeName + '")</script>');
4039

4140
})();

src/CustomElements.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ if (useNative) {
4242

4343
scope.watchShadow = nop;
4444
scope.watchAllShadows = nop;
45+
scope.upgrade = nop;
4546
scope.upgradeAll = nop;
4647
scope.upgradeSubtree = nop;
4748
scope.observeDocument = nop;
@@ -211,10 +212,10 @@ if (useNative) {
211212
// flag as upgraded
212213
inElement.__upgraded__ = true;
213214
// there should never be a shadow root on inElement at this point
214-
// we require child nodes be upgraded before ready
215+
// we require child nodes be upgraded before `created`
215216
scope.upgradeSubtree(inElement);
216217
// lifecycle management
217-
ready(inElement);
218+
created(inElement);
218219
// OUTPUT
219220
return inElement;
220221
}
@@ -256,10 +257,10 @@ if (useNative) {
256257
}
257258
}
258259

259-
function ready(inElement) {
260-
// invoke readyCallback
261-
if (inElement.readyCallback) {
262-
inElement.readyCallback();
260+
function created(inElement) {
261+
// invoke createdCallback
262+
if (inElement.createdCallback) {
263+
inElement.createdCallback();
263264
}
264265
}
265266

@@ -302,12 +303,14 @@ if (useNative) {
302303
};
303304
}
304305

305-
function createElement(inTag) {
306-
var definition = registry[inTag];
306+
function createElement(tag, typeExtension) {
307+
// TODO(sjmiles): ignore 'tag' when using 'typeExtension', we could
308+
// error check it, or perhaps there should only ever be one argument
309+
var definition = registry[typeExtension || tag];
307310
if (definition) {
308311
return new definition.ctor();
309312
}
310-
return domCreateElement(inTag);
313+
return domCreateElement(tag, typeExtension);
311314
}
312315

313316
function upgradeElement(inElement) {

src/HTMLElementElement.js

Lines changed: 0 additions & 134 deletions
This file was deleted.

src/Observer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function inserted(element) {
118118
// TODO(sjmiles): when logging, do work on all custom elements so we can
119119
// track behavior even when callbacks not defined
120120
//console.log('inserted: ', element.localName);
121-
if (element.insertedCallback || (element.__upgraded__ && logFlags.dom)) {
121+
if (element.enteredDocumentCallback || (element.__upgraded__ && logFlags.dom)) {
122122
logFlags.dom && console.group('inserted:', element.localName);
123123
if (inDocument(element)) {
124124
element.__inserted = (element.__inserted || 0) + 1;
@@ -130,9 +130,9 @@ function inserted(element) {
130130
if (element.__inserted > 1) {
131131
logFlags.dom && console.warn('inserted:', element.localName,
132132
'insert/remove count:', element.__inserted)
133-
} else if (element.insertedCallback) {
133+
} else if (element.enteredDocumentCallback) {
134134
logFlags.dom && console.log('inserted:', element.localName);
135-
element.insertedCallback();
135+
element.enteredDocumentCallback();
136136
}
137137
}
138138
logFlags.dom && console.groupEnd();
@@ -149,7 +149,7 @@ function removedNode(node) {
149149
function removed(element) {
150150
// TODO(sjmiles): temporary: do work on all custom elements so we can track
151151
// behavior even when callbacks not defined
152-
if (element.removedCallback || (element.__upgraded__ && logFlags.dom)) {
152+
if (element.leftDocumentCallback || (element.__upgraded__ && logFlags.dom)) {
153153
logFlags.dom && console.log('removed:', element.localName);
154154
if (!inDocument(element)) {
155155
element.__inserted = (element.__inserted || 0) - 1;
@@ -161,8 +161,8 @@ function removed(element) {
161161
if (element.__inserted < 0) {
162162
logFlags.dom && console.warn('removed:', element.localName,
163163
'insert/remove count:', element.__inserted)
164-
} else if (element.removedCallback) {
165-
element.removedCallback();
164+
} else if (element.leftDocumentCallback) {
165+
element.leftDocumentCallback();
166166
}
167167
}
168168
}

src/Parser.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ var IMPORT_LINK_TYPE = window.HTMLImports ? HTMLImports.IMPORT_LINK_TYPE : 'none
1414

1515
var parser = {
1616
selectors: [
17-
'link[rel=' + IMPORT_LINK_TYPE + ']',
18-
'element'
17+
'link[rel=' + IMPORT_LINK_TYPE + ']'
1918
],
2019
map: {
21-
link: 'parseLink',
22-
element: 'parseElement'
20+
link: 'parseLink'
2321
},
2422
parse: function(inDocument) {
2523
if (!inDocument.__parsed) {
@@ -48,9 +46,6 @@ var parser = {
4846
if (linkElt.content) {
4947
parser.parse(linkElt.content);
5048
}
51-
},
52-
parseElement: function(inElementElt) {
53-
new HTMLElementElement(inElementElt);
5449
}
5550
};
5651

test/html/attributes.html

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,24 @@
77
<script src="../../custom-elements.js"></script>
88
</head>
99
<body>
10-
<element name="x-foo">
11-
<script>
12-
(this !== window) && this.register({
13-
prototype: {
14-
removeAttributeOk: false,
15-
setAttributeOk: false,
16-
attributeChangedOk: false,
17-
removeAttribute: function(name) {
18-
this.removeAttributeOk = true;
19-
return HTMLElement.prototype.removeAttribute.call(this, name);
20-
},
21-
setAttribute: function(name, value) {
22-
this.setAttributeOk = true;
23-
HTMLElement.prototype.setAttribute.call(this, name, value);
24-
},
25-
attributeChangedCallback: function(name) {
26-
this.attributeChangedOk = (name == 'squid');
27-
}
28-
}
29-
});
30-
</script>
31-
</element>
3210
<script>
11+
var prototype = Object.create(HTMLElement.prototype);
12+
prototype.removeAttributeOk = false;
13+
prototype.setAttributeOk = false;
14+
prototype.attributeChangedOk = false;
15+
prototype.removeAttribute = function(name) {
16+
this.removeAttributeOk = true;
17+
return HTMLElement.prototype.removeAttribute.call(this, name);
18+
};
19+
prototype.setAttribute = function(name, value) {
20+
this.setAttributeOk = true;
21+
HTMLElement.prototype.setAttribute.call(this, name, value);
22+
};
23+
prototype.attributeChangedCallback = function(name) {
24+
this.attributeChangedOk = (name == 'squid');
25+
};
26+
document.register('x-foo', {prototype: prototype});
27+
3328
addEventListener('WebComponentsReady', function() {
3429
var xfoo = document.createElement('x-foo');
3530
chai.assert.isFalse(xfoo.removeAttributeOk);

0 commit comments

Comments
 (0)