Skip to content

Commit

Permalink
Add beforeRegister; ES6 class must set proto metadata here. Fixes Pol…
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf authored and Martin MOIZARD-LANVIN committed Sep 8, 2015
1 parent 02e180e commit 4e1c81d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/lib/base.html
Expand Up @@ -26,8 +26,9 @@
registerCallback: function() {
// TODO(sjmiles): perhaps this method should be called from polymer-bootstrap?
this._desugarBehaviors(); // abstract
this._doBehavior('registered'); // abstract
this._doBehavior('beforeRegister'); // abstract
this._registerFeatures(); // abstract
this._doBehavior('registered'); // abstract
},

createdCallback: function() {
Expand Down
24 changes: 13 additions & 11 deletions src/lib/dom-module.html
Expand Up @@ -67,18 +67,20 @@
* at the specified `id`.
*/
import: function(id, selector) {
var m = findModule(id);
if (!m) {
// If polyfilling, a script can run before a dom-module element
// is upgraded. We force the containing document to upgrade
// and try again to workaround this polyfill limitation.
forceDocumentUpgrade();
m = findModule(id);
}
if (m && selector) {
m = m.querySelector(selector);
if (id) {
var m = findModule(id);
if (!m) {
// If polyfilling, a script can run before a dom-module element
// is upgraded. We force the containing document to upgrade
// and try again to workaround this polyfill limitation.
forceDocumentUpgrade();
m = findModule(id);
}
if (m && selector) {
m = m.querySelector(selector);
}
return m;
}
return m;
}

});
Expand Down
49 changes: 34 additions & 15 deletions test/unit/behaviors-elements.html
Expand Up @@ -219,26 +219,45 @@

</dom-module>

<dom-module id="registration-behaviors">
<dom-module id="behavior-as-is">

<script>
<template><div id="content"></div></template>

Polymer.registerBehavior ={
registered: function() {
this.is = this.as;
}
};
</dom-module>

Polymer({
<script>

behaviors: [
Polymer.registerBehavior
],
Polymer.registerBehavior ={
beforeRegister: function() {
this.is = this.as;
this.properties = {
prop: {
observer: 'propChanged1'
}
};
this.hostAttributes = {
attr: true
};
this.observers = [
'propChanged2(prop)'
];
},
propChanged1: function() {
this.propChanged1Called = true;
},
propChanged2: function() {
this.propChanged2Called = true;
}
};

as: 'behavior-as-is'
Polymer({

});
behaviors: [
Polymer.registerBehavior
],

</script>
as: 'behavior-as-is'

});

</dom-module>
</script>
7 changes: 6 additions & 1 deletion test/unit/behaviors.html
Expand Up @@ -52,9 +52,14 @@
assert.equal(typeof el._setHasOptionsA, 'function');
});

test('registered behavior', function() {
test('beforeRegister behavior', function() {
var el = document.createElement('behavior-as-is');
assert.equal(el.is, 'behavior-as-is');
assert.ok(el.$.content);
el.prop = 42;
assert.isTrue(el.propChanged1Called);
assert.isTrue(el.propChanged2Called);
assert.isTrue(el.hasAttribute('attr'));
});

});
Expand Down

0 comments on commit 4e1c81d

Please sign in to comment.