Permalink
Browse files

Added document-register-element/pony CommonJS module.

As discussed in issue #86 there is currently no way to require
document-register-element polyfill without polluting the global
context after feature detection.

Since there could be some very specific case when the browser
should be force-patched, the `pony` version of the module
will not attempt to feature detect anything and it will only
enrich the environment once invoked.

```
const installCE = require('document-register-element/pony');
installCE(global, 'force');

// second argument is optional
// it defaults to 'auto' which
// uses feature detection only
```
  • Loading branch information...
1 parent c710e66 commit e6def74da1996bf7c643fbee10fe7d095a80ae23 @WebReflection committed Nov 7, 2016
View
@@ -88,7 +88,10 @@ dreie8:
# build node.js version
node:
mkdir -p build
+ mkdir -p pony
cat template/license.before LICENSE.txt template/license.after template/node.before $(NODE) template/node.after >build/$(REPO).node.js
+ cp build/$(REPO).node.js pony/index.js
+ echo 'installCustomElements(global);'>>build/$(REPO).node.js
# build AMD version
amd:
Oops, something went wrong.
Oops, something went wrong.
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-define(function(){'use strict';
+define(function(polyfill){'use strict';
// DO NOT USE THIS FILE DIRECTLY, IT WON'T WORK
// THIS IS A PROJECT BASED ON A BUILD SYSTEM
@@ -433,7 +433,12 @@ define(function(){'use strict';
}));
- var
+
+ // passed at runtime, configurable
+ // via nodejs module
+ if (!polyfill) polyfill = 'auto';
+
+ var
// V0 polyfill entry
REGISTER_ELEMENT = 'registerElement',
@@ -513,7 +518,7 @@ define(function(){'use strict';
fixGetClass = false,
DRECEV1 = '__dreCEv1',
customElements = window.customElements,
- usableCustomElements = !!(
+ usableCustomElements = polyfill !== 'force' && !!(
customElements &&
customElements.define &&
customElements.get &&
@@ -1382,7 +1387,7 @@ define(function(){'use strict';
}
// if customElements is not there at all
- if (!customElements) polyfillV1();
+ if (!customElements || polyfill === 'force') polyfillV1();
else {
// if available test extends work as expected
try {
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-(function(window){'use strict';
+(function(window, polyfill){'use strict';
// DO NOT USE THIS FILE DIRECTLY, IT WON'T WORK
// THIS IS A PROJECT BASED ON A BUILD SYSTEM
@@ -433,7 +433,12 @@ THE SOFTWARE.
}));
- var
+
+ // passed at runtime, configurable
+ // via nodejs module
+ if (!polyfill) polyfill = 'auto';
+
+ var
// V0 polyfill entry
REGISTER_ELEMENT = 'registerElement',
@@ -513,7 +518,7 @@ THE SOFTWARE.
fixGetClass = false,
DRECEV1 = '__dreCEv1',
customElements = window.customElements,
- usableCustomElements = !!(
+ usableCustomElements = polyfill !== 'force' && !!(
customElements &&
customElements.define &&
customElements.get &&
@@ -1382,7 +1387,7 @@ THE SOFTWARE.
}
// if customElements is not there at all
- if (!customElements) polyfillV1();
+ if (!customElements || polyfill === 'force') polyfillV1();
else {
// if available test extends work as expected
try {
@@ -21,7 +21,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-function installCustomElements(window) {'use strict';
+// global window Object
+// optional polyfill info
+// 'auto' used by default, everything is feature detected
+// 'force' use the polyfill even if not fully needed
+function installCustomElements(window, polyfill) {'use strict';
// DO NOT USE THIS FILE DIRECTLY, IT WON'T WORK
// THIS IS A PROJECT BASED ON A BUILD SYSTEM
@@ -432,7 +436,12 @@ function installCustomElements(window) {'use strict';
}));
- var
+
+ // passed at runtime, configurable
+ // via nodejs module
+ if (!polyfill) polyfill = 'auto';
+
+ var
// V0 polyfill entry
REGISTER_ELEMENT = 'registerElement',
@@ -512,7 +521,7 @@ function installCustomElements(window) {'use strict';
fixGetClass = false,
DRECEV1 = '__dreCEv1',
customElements = window.customElements,
- usableCustomElements = !!(
+ usableCustomElements = polyfill !== 'force' && !!(
customElements &&
customElements.define &&
customElements.get &&
@@ -1381,7 +1390,7 @@ function installCustomElements(window) {'use strict';
}
// if customElements is not there at all
- if (!customElements) polyfillV1();
+ if (!customElements || polyfill === 'force') polyfillV1();
else {
// if available test extends work as expected
try {
@@ -1420,6 +1429,5 @@ function installCustomElements(window) {'use strict';
}
-installCustomElements(global);
-
module.exports = installCustomElements;
+installCustomElements(global);
Oops, something went wrong.

0 comments on commit e6def74

Please sign in to comment.