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

Execute initializers in their respective context #10179

Merged
merged 1 commit into from
Jan 13, 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
7 changes: 7 additions & 0 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ for a detailed explanation.

## Feature Flags

* `ember-application-initializer-context`

Sets the context of the initializer function to its object instead of the
global object.

Added in [#10179](https://github.com/emberjs/ember.js/pull/10179).

* `ember-testing-checkbox-helpers`

Add `check` and `uncheck` test helpers.
Expand Down
3 changes: 2 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"new-computed-syntax": null,
"ember-testing-checkbox-helpers": null,
"ember-metal-stream": null,
"ember-htmlbars-each-with-index": true
"ember-htmlbars-each-with-index": true,
"ember-application-initializer-context": null
},
"debugStatements": [
"Ember.warn",
Expand Down
10 changes: 8 additions & 2 deletions packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,13 +695,19 @@ var Application = Namespace.extend(DeferredMixin, {

for (var i = 0; i < initializers.length; i++) {
initializer = initializersByName[initializers[i]];
graph.addEdges(initializer.name, initializer.initialize, initializer.before, initializer.after);
graph.addEdges(initializer.name, initializer, initializer.before, initializer.after);
}

graph.topsort(function (vertex) {
var initializer = vertex.value;
Ember.assert("No application initializer named '" + vertex.name + "'", !!initializer);
initializer(registry, namespace);

if (Ember.FEATURES.isEnabled("ember-application-initializer-context")) {
initializer.initialize(registry, namespace);
} else {
var ref = initializer.initialize;
ref(registry, namespace);
}
});
},

Expand Down
22 changes: 22 additions & 0 deletions packages/ember-application/tests/system/initializers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,25 @@ test("initializers are per-app", function() {
initialize: function(registry) {}
});
});

if (Ember.FEATURES.isEnabled("ember-application-initializer-context")) {
test("initializers should be executed in their own context", function() {
expect(1);
var MyApplication = Application.extend();

MyApplication.initializer({
name: 'coolBabeInitializer',
myProperty: 'coolBabe',
initialize: function(registry, application) {
equal(this.myProperty, 'coolBabe', 'should have access to its own context');
}
});

run(function() {
app = MyApplication.create({
router: false,
rootElement: '#qunit-fixture'
});
});
});
}