Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Unified Diff: third_party/polymer/v0_8/components-chromium/polymer/src/micro/constructor-extracted.js

Issue 1082403004: Import Polymer 0.8 and several key elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also remove polymer/explainer Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v0_8/components-chromium/polymer/src/micro/constructor-extracted.js
diff --git a/third_party/polymer/v0_8/components-chromium/polymer/src/micro/constructor-extracted.js b/third_party/polymer/v0_8/components-chromium/polymer/src/micro/constructor-extracted.js
new file mode 100644
index 0000000000000000000000000000000000000000..03cc04149ffb37edb1d436b76abda27ec5667e9a
--- /dev/null
+++ b/third_party/polymer/v0_8/components-chromium/polymer/src/micro/constructor-extracted.js
@@ -0,0 +1,60 @@
+
+
+ /**
+ * Generates a boilerplate constructor.
+ *
+ * XFoo = Polymer({
+ * is: 'x-foo'
+ * });
+ * ASSERT(new XFoo() instanceof XFoo);
+ *
+ * You can supply a custom constructor on the prototype. But remember that
+ * this constructor will only run if invoked **manually**. Elements created
+ * via `document.createElement` or from HTML _will not invoke this method_.
+ *
+ * Instead, we reuse the concept of `constructor` for a factory method which
+ * can take arguments.
+ *
+ * MyFoo = Polymer({
+ * is: 'my-foo',
+ * constructor: function(foo) {
+ * this.foo = foo;
+ * }
+ * ...
+ * });
+ *
+ * @class base feature: constructor
+ */
+
+ Polymer.Base._addFeature({
+
+ // registration-time
+
+ _prepConstructor: function() {
+ // support both possible `createElement` signatures
+ this._factoryArgs = this.extends ? [this.extends, this.is] : [this.is];
+ // thunk the constructor to delegate allocation to `createElement`
+ var ctor = function() {
+ return this._factory(arguments);
+ };
+ if (this.hasOwnProperty('extends')) {
+ ctor.extends = this.extends;
+ }
+ // ensure constructor is set. The `constructor` property is
+ // not writable on Safari; note: Chrome requires the property
+ // to be configurable.
+ Object.defineProperty(this, 'constructor', {value: ctor,
+ writable: true, configurable: true});
+ ctor.prototype = this;
+ },
+
+ _factory: function(args) {
+ var elt = document.createElement.apply(document, this._factoryArgs);
+ if (this.factoryImpl) {
+ this.factoryImpl.apply(elt, args);
+ }
+ return elt;
+ }
+
+ });
+

Powered by Google App Engine
This is Rietveld 408576698