Skip to content

Commit

Permalink
Removes "created" lifecycle function, since constructor can be used f…
Browse files Browse the repository at this point in the history
…or this now
  • Loading branch information
mairatma committed Jun 1, 2015
1 parent 48ced54 commit fd1877c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 53 deletions.
15 changes: 0 additions & 15 deletions src/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ import EventsCollector from './EventsCollector';
* super(config);
* }
*
* created() {
* }
*
* decorateInternal() {
* }
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -498,7 +484,6 @@ class Component extends Attribute {
*/
created_() {
this.on('attrsChanged', this.handleAttributesChanges_);
this.created();
}

/**
Expand Down
84 changes: 46 additions & 38 deletions test/src/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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: {}
};
Expand All @@ -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',
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit fd1877c

Please sign in to comment.