Skip to content

Commit

Permalink
Merge pull request #2363 from stefanpenner/improveInitialization
Browse files Browse the repository at this point in the history
$.ready initializations should not auto run.
  • Loading branch information
stefanpenner committed Mar 28, 2013
2 parents f557e37 + 7b89740 commit 8a4e6af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 46 deletions.
12 changes: 5 additions & 7 deletions packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,13 @@ var Application = Ember.Application = Ember.Namespace.extend(Ember.DeferredMixin
scheduleInitialize: function() {
var self = this;

function initialize(){
if (self.isDestroyed) { return; }
Ember.run.schedule('actions', self, 'initialize');
}

if (!this.$ || this.$.isReady) {
initialize();
Ember.run.schedule('actions', self, 'initialize');
} else {
this.$().ready(initialize);
this.$().ready(function(){
if (self.isDestroyed) { return; }
Ember.run(self, 'initialize');
});
}
},

Expand Down
43 changes: 4 additions & 39 deletions packages/ember-application/tests/system/readiness_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ test("Ember.Application's ready event is called right away if jQuery is already
equal(wasResolved, 1);
equal(readyWasCalled, 1, "ready was called");

Ember.run(function() {
domReady();
});
domReady();

equal(wasResolved, 1);
equal(readyWasCalled, 1, "application's ready was not called again");
Expand All @@ -93,35 +91,7 @@ test("Ember.Application's ready event is called after the document becomes ready
equal(readyWasCalled, 0, "ready wasn't called yet");
equal(wasResolved, 0);

Ember.run(function() {
domReady();
equal(wasResolved, 0);
});

equal(wasResolved, 1);
equal(readyWasCalled, 1, "ready was called now that DOM is ready");
});

test("Ember.Application's ready event is called after the document becomes ready without initialize if autoinit is set", function() {
var wasResolved = 0;
Ember.run(function() {
application = Application.create({
router: false,
autoinit: true
});
application.then(function(){
wasResolved++;
});
equal(wasResolved, 0);
});

equal(readyWasCalled, 0, "ready wasn't called yet");
equal(wasResolved, 0);

Ember.run(function() {
domReady();
equal(wasResolved, 0);
});
domReady();

equal(wasResolved, 1);
equal(readyWasCalled, 1, "ready was called now that DOM is ready");
Expand All @@ -141,10 +111,7 @@ test("Ember.Application's ready event can be deferred by other components", func

equal(readyWasCalled, 0, "ready wasn't called yet");

Ember.run(function() {
domReady();
equal(wasResolved, 0);
});
domReady();

equal(readyWasCalled, 0, "ready wasn't called yet");
equal(wasResolved, 0);
Expand Down Expand Up @@ -172,9 +139,7 @@ test("Ember.Application's ready event can be deferred by other components", func
equal(wasResolved, 0);
});

Ember.run(function() {
domReady();
});
domReady();

equal(readyWasCalled, 0, "ready wasn't called yet");

Expand Down

0 comments on commit 8a4e6af

Please sign in to comment.