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

Commit

Permalink
workaround for PolymerBase mixin API incompatibility with super() imp…
Browse files Browse the repository at this point in the history
…lementation
  • Loading branch information
Scott J. Miles committed Dec 16, 2013
1 parent 75e9b42 commit e502294
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
41 changes: 31 additions & 10 deletions src/declaration/prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,39 @@
},
// install Polymer instance api into prototype chain, as needed
ensureBaseApi: function(prototype) {
if (!prototype.PolymerBase) {
prototype = Object.create(prototype);
// we need a unique copy of base api for each base prototype
// therefore we 'extend' here instead of simply chaining
// we could memoize instead, especially for the common cases,
// in particular, for base === HTMLElement.prototype
for (var n in api.instance) {
extend(prototype, api.instance[n]);
}
if (prototype.PolymerBase) {
return prototype;
}
var extended = Object.create(prototype);
// we need a unique copy of base api for each base prototype
// therefore we 'extend' here instead of simply chaining
// we could memoize instead, especially for the common cases,
// in particular, for base === HTMLElement.prototype
for (var n in api.instance) {
extend(extended, api.instance[n]);
}
// TODO(sjmiles): sharing methods across prototype chains is
// not supported by our 'super' implementation which optimizes
// by memoizing prototype relationships.
// Probably we should have a version of 'extend' that is
// share-aware: it could study the text of each function,
// look for usage of 'super', and wrap those functions in
// closures.
// As of now, there is only one problematic method, so
// we just patch it manually.
this.mixinMethod(extended, prototype, api.instance.mdv, 'bind');
// return buffed-up prototype
return prototype;
return extended;
},
mixinMethod: function(extended, prototype, api, name) {
var $super = function(args) {
prototype[name].apply(this, args);
};
extended[name] = function() {
this.super = $super;
api[name].apply(this, arguments);
this.super = extended.super;
}
},
// ensure prototype[name] inherits from a prototype.prototype[name]
inheritObject: function(name, prototype, base) {
Expand Down
7 changes: 7 additions & 0 deletions src/instance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,19 @@
}
};

// no-operation function for handy stubs
var nop = function() {};
// null-object for handy stubs
var nob = {};

// deprecated

utils.asyncMethod = utils.async;

// exports

scope.api.instance.utils = utils;
scope.nop = nop;
scope.nob = nob;

})(Polymer);
2 changes: 1 addition & 1 deletion src/lib/super.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// $super must be installed on an instance or prototype chain
// as `super`, and invoked via `this`, e.g.
// `this.super();`

// will not work if function objects are not unique, for example,
// when using mixins.
// The memoization strategy assumes each function exists on only one
Expand Down

0 comments on commit e502294

Please sign in to comment.