diff --git a/src/component/Component.js b/src/component/Component.js index bdb455f8..5cd82087 100644 --- a/src/component/Component.js +++ b/src/component/Component.js @@ -32,9 +32,6 @@ import EventsCollector from './EventsCollector'; * super(config); * } * - * created() { - * } - * * decorateInternal() { * } * @@ -378,17 +375,6 @@ class Component extends Attribute { return element.innerHTML; } - /** - * Lifecycle. Creation phase of the component happens once after the - * component is instantiated, therefore its the initial phase of the - * component Lifecycle. Be conscious about actions performed in this phase - * to not compromise instantiation time with operations that can be - * postponed to further phases. It's recommended to bind component custom - * events in this phase, in contrast to DOM events that must be bind on - * attach phase. - */ - created() {} - /** * Creates a surface that was found via a string placeholder. * @param {string?} surfaceId @@ -498,7 +484,6 @@ class Component extends Attribute { */ created_() { this.on('attrsChanged', this.handleAttributesChanges_); - this.created(); } /** diff --git a/test/src/component/Component.js b/test/src/component/Component.js index 3bbf762d..727eaa44 100644 --- a/test/src/component/Component.js +++ b/test/src/component/Component.js @@ -24,13 +24,11 @@ describe('Component', function() { custom.render(); sinon.assert.callOrder( - CustomComponent.prototype.created, CustomComponent.prototype.renderInternal, CustomComponent.prototype.getSurfaceContent, CustomComponent.prototype.attached ); - sinon.assert.callCount(CustomComponent.prototype.created, 1); sinon.assert.callCount(CustomComponent.prototype.renderInternal, 1); sinon.assert.callCount(CustomComponent.prototype.attached, 1); @@ -54,12 +52,10 @@ describe('Component', function() { custom.decorate(); sinon.assert.callOrder( - CustomComponent.prototype.created, CustomComponent.prototype.decorateInternal, CustomComponent.prototype.getSurfaceContent, CustomComponent.prototype.attached); - sinon.assert.callCount(CustomComponent.prototype.created, 1); sinon.assert.callCount(CustomComponent.prototype.decorateInternal, 1); sinon.assert.callCount(CustomComponent.prototype.attached, 1); @@ -398,10 +394,12 @@ describe('Component', function() { it('should render component on specified default parent if no parent is specified', function() { var defaultParent = document.createElement('div'); - var CustomComponent = createCustomComponentClass(); - CustomComponent.prototype.created = function() { - this.DEFAULT_ELEMENT_PARENT = defaultParent; - }; + class CustomComponent extends Component { + constructor(opt_config) { + super(opt_config); + this.DEFAULT_ELEMENT_PARENT = defaultParent; + } + } var custom = new CustomComponent(); custom.render(); @@ -1128,18 +1126,20 @@ describe('Component', function() { }); it('should instantiate sub component from placeholder passing defined config data', function() { - var CustomComponent = createCustomComponentClass(); + class CustomComponent extends Component { + constructor(opt_config) { + super(opt_config); + Component.componentsCollector.setNextComponentData('child', { + foo: this.foo + }); + } + } CustomComponent.ATTRS = { foo: {} }; CustomComponent.prototype.getElementContent = function() { return '%%%%~c-child:ChildComponent~%%%%'; }; - CustomComponent.prototype.created = function() { - Component.componentsCollector.setNextComponentData('child', { - foo: this.foo - }); - }; var custom = new CustomComponent({ foo: 'foo', @@ -1183,18 +1183,20 @@ describe('Component', function() { dom.append(document.body, element); var fooElement = document.body.querySelector('span'); - var CustomComponent = createCustomComponentClass(); + class CustomComponent extends Component { + constructor(opt_config) { + super(opt_config); + Component.componentsCollector.setNextComponentData('child', { + foo: this.foo + }); + } + } CustomComponent.ATTRS = { foo: {} }; CustomComponent.prototype.getElementContent = function() { return '%%%%~c-child:ChildComponent~%%%%'; }; - CustomComponent.prototype.created = function() { - Component.componentsCollector.setNextComponentData('child', { - foo: this.foo - }); - }; var custom = new CustomComponent({ element: '#custom', @@ -1212,18 +1214,20 @@ describe('Component', function() { dom.append(document.body, element); var fooElement = document.body.querySelector('span'); - var CustomComponent = createCustomComponentClass(); + class CustomComponent extends Component { + constructor(opt_config) { + super(opt_config); + Component.componentsCollector.setNextComponentData('child', { + foo: this.foo + }); + } + } CustomComponent.ATTRS = { foo: {} }; CustomComponent.prototype.getElementContent = function() { return '%%%%~c-child:ChildComponent~%%%%'; }; - CustomComponent.prototype.created = function() { - Component.componentsCollector.setNextComponentData('child', { - foo: this.foo - }); - }; var custom = new CustomComponent({ element: '#custom', @@ -1235,7 +1239,19 @@ describe('Component', function() { }); it('should update existing component from placeholder', function(done) { - var CustomComponent = createCustomComponentClass(); + class CustomComponent extends Component { + constructor(opt_config) { + super(opt_config); + Component.componentsCollector.setNextComponentData('child', { + foo: this.foo + }); + this.on('fooChanged', function() { + Component.componentsCollector.setNextComponentData('child', { + foo: this.foo + }); + }); + } + } CustomComponent.ATTRS = { foo: {} }; @@ -1250,16 +1266,6 @@ describe('Component', function() { CustomComponent.prototype.getSurfaceContent = function(surfaceId) { return surfaceId === 'foo' ? 'Surface ' + this.foo + ': %%%%~c-child:ChildComponent~%%%%' : ''; }; - CustomComponent.prototype.created = function() { - Component.componentsCollector.setNextComponentData('child', { - foo: this.foo - }); - this.on('fooChanged', function() { - Component.componentsCollector.setNextComponentData('child', { - foo: this.foo - }); - }); - }; var custom = new CustomComponent({ foo: 'foo', @@ -1554,10 +1560,12 @@ describe('Component', function() { class CustomComponent extends Component { constructor(opt_config) { super(opt_config); + if (this.created) { + this.created(); + } } } - sinon.spy(CustomComponent.prototype, 'created'); sinon.spy(CustomComponent.prototype, 'decorateInternal'); sinon.spy(CustomComponent.prototype, 'getSurfaceContent'); sinon.spy(CustomComponent.prototype, 'attached');