Skip to content

Instantly share code, notes, and snippets.

@lukes
Last active August 29, 2015 14:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukes/af67d1dae2702b92ac8e to your computer and use it in GitHub Desktop.
Save lukes/af67d1dae2702b92ac8e to your computer and use it in GitHub Desktop.
Using Ember.ObjectProxy for currentUser
// (Rename to current-user.js and place in /initializers)
// Ember now complains that you can't type inject a controller into a controller
// so use an Ember.ObjectProxy for currentUser instead.
//
// Ember.ObjectProxy allows you to set a content value, and will delegate
// all getters and setters to its content.
import DS from "ember-data";
import CurrentUser from "../models/current-user";
export default {
name: 'currentUser',
after: 'store',
initialize: function(container, application) {
var store = container.lookup('store:main');
var user = store.push('user', { id: 1, first_name: 'User', last_name: 'Name' });
container.register('user:current', CurrentUser, { singleton: true });
// .create() our singleton user and set its content
var currentUser = container.lookup('user:current');
currentUser.set('content', user);
container.typeInjection('controller', 'currentUser', 'user:current');
container.typeInjection('route', 'currentUser', 'user:current');
container.typeInjection('view', 'currentUser', 'user:current');
}
};
// (Rename to current-user.js and place in /models)
import Ember from 'ember';
export default Ember.ObjectProxy.extend(Ember.PromiseProxyMixin, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment