Permalink
Browse files

Give the store to injected controllers

  • Loading branch information...
Tomhuda Katzdale
Tomhuda Katzdale committed Jun 19, 2012
1 parent f0d3e72 commit 37d3319360be4e8f242a39111290a844720af3ab
@@ -11,4 +11,18 @@ Ember.onLoad('application', function(app) {
}
}
});
app.registerInjection({
name: "giveStoreToControllers",
injection: function(app, stateManager, property) {
if (property.match(/Controller$/)) {
var controllerName = property.charAt(0).toLowerCase() + property.substr(1);
var store = stateManager.get('store');
var controller = stateManager.get(controllerName);
controller.set('store', store);
}
}
});
});
@@ -0,0 +1,35 @@
var app;
module("Application boot", {
setup: function() {
var Router = Ember.Router.extend({
root: Ember.Route.extend()
});
Ember.run(function() {
app = Ember.Application.create({
Router: Router,
Store: DS.Store,
FooController: Ember.Controller.extend()
});
});
},
teardown: function() {
Ember.run(function() {
app.destroy();
});
}
});
test("It injects the store into the router", function() {
app.initialize();
ok(app.getPath('stateManager.store') instanceof DS.Store, "the store was injected");
});
test("It injects the store into controllers", function() {
app.initialize();
ok(app.getPath('stateManager.fooController.store') instanceof DS.Store, "the store was injected");
});

1 comment on commit 37d3319

@bradleypriest

This comment has been minimized.

Show comment
Hide comment
@bradleypriest

bradleypriest Jun 21, 2012

Member

I'm getting an error against master with this change.
Unable to delegate set without content for property: store

It looks like because the controller has no store method it tries to delegate to the content instead.

I've fixed it in my code with:
Ember.ControllerMixin.reopen({store: null})

Member

bradleypriest commented on 37d3319 Jun 21, 2012

I'm getting an error against master with this change.
Unable to delegate set without content for property: store

It looks like because the controller has no store method it tries to delegate to the content instead.

I've fixed it in my code with:
Ember.ControllerMixin.reopen({store: null})

Please sign in to comment.