Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking: Initialize behaviors before module #112

Merged
merged 1 commit into from
Oct 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,6 @@ Box.Application = (function() {

instances[element.id] = instanceData;

callModuleMethod(instanceData.instance, 'init');

var moduleBehaviors = getBehaviors(instanceData),
behaviorInstance;

Expand All @@ -501,6 +499,10 @@ Box.Application = (function() {
callModuleMethod(behaviorInstance, 'init');
}

// Initialize module only after behaviors are initialized
callModuleMethod(instanceData.instance, 'init');

// Bind events after initialization is complete to avoid event timing issues
bindEventListeners(instanceData);

}
Expand Down
5 changes: 3 additions & 2 deletions tests/application-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('Box.Application', function() {
Box.Application.start(testModule);
});

it('should call init() on module and behaviors in order they are defined when called', function() {
it('should call init() behaviors in order they are defined and then the module when called', function() {
var moduleInitSpy = sandbox.spy(),
behaviorInitSpy = sandbox.spy(),
behavior2InitSpy = sandbox.spy();
Expand All @@ -162,8 +162,9 @@ describe('Box.Application', function() {
}));
Box.Application.start(testModule);

assert.ok(moduleInitSpy.calledBefore(behaviorInitSpy), 'module init called before first behavior init');
assert.ok(behaviorInitSpy.calledBefore(behavior2InitSpy), 'first behavior init called before second behavior init');
assert.ok(behavior2InitSpy.calledBefore(moduleInitSpy), 'module init called after second behavior init');

});

it('should emit an error event when not in debug mode', function() {
Expand Down