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

Commit d817018

Browse files
committed
Refactor build boot process
Move loader and flag parsing out of "if shadowdom polyfill" branch code This change makes the "native" build possible
1 parent 6e1372e commit d817018

File tree

4 files changed

+69
-60
lines changed

4 files changed

+69
-60
lines changed

build-native.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2+
"build/boot.js",
23
"src/patches-shadowdom-native.js",
34

45
"src/lang.js",

build.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2+
"build/boot.js",
23
"../WeakMap/weakmap.js",
34
"../observe-js/src/observe.js",
45
"build/if-poly.js",

build/boot.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3+
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4+
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5+
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6+
* Code distributed by Google as part of the polymer project is also
7+
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
8+
*/
9+
10+
window.Platform = window.Platform || {};
11+
// prepopulate window.logFlags if necessary
12+
window.logFlags = window.logFlags || {};
13+
// process flags
14+
(function(scope){
15+
// import
16+
var flags = scope.flags || {};
17+
// populate flags from location
18+
location.search.slice(1).split('&').forEach(function(o) {
19+
o = o.split('=');
20+
o[0] && (flags[o[0]] = o[1] || true);
21+
});
22+
var entryPoint = document.currentScript ||
23+
document.querySelector('script[src*="platform.js"]');
24+
if (entryPoint) {
25+
var a = entryPoint.attributes;
26+
for (var i = 0, n; i < a.length; i++) {
27+
n = a[i];
28+
if (n.name !== 'src') {
29+
flags[n.name] = n.value || true;
30+
}
31+
}
32+
}
33+
if (flags.log) {
34+
flags.log.split(',').forEach(function(f) {
35+
window.logFlags[f] = true;
36+
});
37+
}
38+
// If any of these flags match 'native', then force native ShadowDOM; any
39+
// other truthy value, or failure to detect native
40+
// ShadowDOM, results in polyfill
41+
flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill;
42+
if (flags.shadow === 'native') {
43+
flags.shadow = false;
44+
} else {
45+
flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot;
46+
}
47+
48+
if (flags.shadow && document.querySelectorAll('script').length > 1) {
49+
console.warn('platform.js is not the first script on the page. ' +
50+
'See http://www.polymer-project.org/docs/start/platform.html#setup ' +
51+
'for details.');
52+
}
53+
54+
// CustomElements polyfill flag
55+
if (flags.register) {
56+
window.CustomElements = window.CustomElements || {flags: {}};
57+
window.CustomElements.flags.register = flags.register;
58+
}
59+
60+
if (flags.imports) {
61+
window.HTMLImports = window.HTMLImports || {flags: {}};
62+
window.HTMLImports.flags.imports = flags.imports;
63+
}
64+
65+
// export
66+
scope.flags = flags;
67+
})(Platform);

build/if-poly.js

-60
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,2 @@
1-
// prepoulate window.Platform.flags for default controls
2-
window.Platform = window.Platform || {};
3-
// prepopulate window.logFlags if necessary
4-
window.logFlags = window.logFlags || {};
5-
// process flags
6-
(function(scope){
7-
// import
8-
var flags = scope.flags || {};
9-
// populate flags from location
10-
location.search.slice(1).split('&').forEach(function(o) {
11-
o = o.split('=');
12-
o[0] && (flags[o[0]] = o[1] || true);
13-
});
14-
var entryPoint = document.currentScript ||
15-
document.querySelector('script[src*="platform.js"]');
16-
if (entryPoint) {
17-
var a = entryPoint.attributes;
18-
for (var i = 0, n; i < a.length; i++) {
19-
n = a[i];
20-
if (n.name !== 'src') {
21-
flags[n.name] = n.value || true;
22-
}
23-
}
24-
}
25-
if (flags.log) {
26-
flags.log.split(',').forEach(function(f) {
27-
window.logFlags[f] = true;
28-
});
29-
}
30-
// If any of these flags match 'native', then force native ShadowDOM; any
31-
// other truthy value, or failure to detect native
32-
// ShadowDOM, results in polyfill
33-
flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill;
34-
if (flags.shadow === 'native') {
35-
flags.shadow = false;
36-
} else {
37-
flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot;
38-
}
39-
40-
if (flags.shadow && document.querySelectorAll('script').length > 1) {
41-
console.warn('platform.js is not the first script on the page. ' +
42-
'See http://www.polymer-project.org/docs/start/platform.html#setup ' +
43-
'for details.');
44-
}
45-
46-
// CustomElements polyfill flag
47-
if (flags.register) {
48-
window.CustomElements = window.CustomElements || {flags: {}};
49-
window.CustomElements.flags.register = flags.register;
50-
}
51-
52-
if (flags.imports) {
53-
window.HTMLImports = window.HTMLImports || {flags: {}};
54-
window.HTMLImports.flags.imports = flags.imports;
55-
}
56-
57-
// export
58-
scope.flags = flags;
59-
})(Platform);
60-
611
// select ShadowDOM impl
622
if (Platform.flags.shadow) {

0 commit comments

Comments
 (0)