Skip to content

Commit

Permalink
Moves hook to 'renderComponent', this makes it so used are not forced…
Browse files Browse the repository at this point in the history
… to use the static render method.
  • Loading branch information
bryceosterhaus committed Jan 16, 2017
1 parent f543b7e commit 06b837b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 3 additions & 5 deletions packages/metal-component/src/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,6 @@ class Component extends EventEmitter {
element = opt_configOrElement;
}
const instance = new Ctor(config, false);

if (window.__METAL_DEV_TOOLS_HOOK__) {
window.__METAL_DEV_TOOLS_HOOK__(instance);
}

instance.renderComponent(element);
return instance;
}
Expand All @@ -457,6 +452,9 @@ class Component extends EventEmitter {
*/
renderComponent(opt_parentElement) {
if (!this.hasRendererRendered_) {
if (window.__METAL_DEV_TOOLS_HOOK__) {
window.__METAL_DEV_TOOLS_HOOK__(this);
}
this.getRenderer().render(this);
}
this.emit('render');
Expand Down
7 changes: 6 additions & 1 deletion packages/metal-component/test/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ describe('Component', function() {
assert.ok(!Component.isComponentCtor(fn.bind(this)));
});

it('should pass instance of component to __METAL_DEV_TOOLS_HOOK__ in Component.render', function() {
it('should pass instance of component to __METAL_DEV_TOOLS_HOOK__ on first render', function() {
var hookStub = sinon.stub();
window.__METAL_DEV_TOOLS_HOOK__ = hookStub;
class CustomComponent extends Component {
Expand All @@ -957,6 +957,11 @@ describe('Component', function() {
assert.ok(comp.element);
sinon.assert.callCount(hookStub, 1);
sinon.assert.calledWith(hookStub, comp);

comp.visible = false;

sinon.assert.callCount(hookStub, 1);
sinon.assert.calledWith(hookStub, comp);
});

function createCustomComponentClass(opt_rendererContentOrFn) {
Expand Down

0 comments on commit 06b837b

Please sign in to comment.