Skip to content

Commit

Permalink
Merge pull request #11770 from martndemus/remove-controller-needs
Browse files Browse the repository at this point in the history
[CLEANUP beta] Remove deprecated Controller#needs
  • Loading branch information
rwjblue committed Jul 16, 2015
2 parents 68e7fee + 67de390 commit 871cbd6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 335 deletions.
160 changes: 1 addition & 159 deletions packages/ember-application/lib/ext/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,150 +6,15 @@

import Ember from 'ember-metal/core'; // Ember.assert
import { get } from 'ember-metal/property_get';
import EmberError from 'ember-metal/error';
import { inspect } from 'ember-metal/utils';
import { computed } from 'ember-metal/computed';
import ControllerMixin from 'ember-runtime/mixins/controller';
import controllerFor from 'ember-routing/system/controller_for';

function verifyNeedsDependencies(controller, container, needs) {
var dependency, i, l;
var missing = [];

for (i = 0, l = needs.length; i < l; i++) {
dependency = needs[i];

Ember.assert(inspect(controller) + '#needs must not specify dependencies with periods in their names (' +
dependency + ')', dependency.indexOf('.') === -1);

if (dependency.indexOf(':') === -1) {
dependency = 'controller:' + dependency;
}

// Structure assert to still do verification but not string concat in production
if (!container._registry.has(dependency)) {
missing.push(dependency);
}
}
if (missing.length) {
throw new EmberError(inspect(controller) + ' needs [ ' + missing.join(', ') +
' ] but ' + (missing.length > 1 ? 'they' : 'it') + ' could not be found');
}
}

var defaultControllersComputedProperty = computed(function() {
var controller = this;

Ember.deprecate('Controller#needs is deprecated, please use Ember.inject.controller() instead');

return {
needs: get(controller, 'needs'),
container: get(controller, 'container'),
unknownProperty(controllerName) {
var needs = this.needs;
var dependency, i, l;

for (i = 0, l = needs.length; i < l; i++) {
dependency = needs[i];
if (dependency === controllerName) {
return this.container.lookup('controller:' + controllerName);
}
}

var errorMessage = inspect(controller) + '#needs does not include `' +
controllerName + '`. To access the ' +
controllerName + ' controller from ' +
inspect(controller) + ', ' +
inspect(controller) +
' should have a `needs` property that is an array of the controllers it has access to.';
throw new ReferenceError(errorMessage);
},
setUnknownProperty(key, value) {
throw new Error('You cannot overwrite the value of `controllers.' + key + '` of ' + inspect(controller));
}
};
});

/**
@class ControllerMixin
@namespace Ember
@public
*/
ControllerMixin.reopen({
concatenatedProperties: ['needs'],

/**
An array of other controller objects available inside
instances of this controller via the `controllers`
property:
For example, when you define a controller:
```javascript
App.CommentsController = Ember.Controller.extend({
needs: ['post']
});
```
The application's single instance of these other
controllers are accessible by name through the
`controllers` property:
```javascript
this.get('controllers.post'); // instance of App.PostController
```
Given that you have a nested controller (nested routes):
```javascript
App.CommentsNewController = Ember.Controller.extend({
});
```
When you define a controller that requires access to a nested one:
```javascript
App.IndexController = Ember.Controller.extend({
needs: ['commentsNew']
});
```
You will be able to get access to it:
```javascript
this.get('controllers.commentsNew'); // instance of App.CommentsNewController
```
This is only available for singleton controllers.
@deprecated Use `Ember.inject.controller()` instead.
@property {Array} needs
@default []
@public
*/
needs: [],

init() {
var needs = get(this, 'needs');
var length = get(needs, 'length');

if (length > 0) {
Ember.assert(' `' + inspect(this) + ' specifies `needs`, but does ' +
'not have a container. Please ensure this controller was ' +
'instantiated with a container.',
this.container || this.controllers !== defaultControllersComputedProperty);

if (this.container) {
verifyNeedsDependencies(this, this.container, needs);
}

// if needs then initialize controllers proxy
get(this, 'controllers');
}

this._super(...arguments);
},

/**
@method controllerFor
@see {Ember.Route#controllerFor}
Expand All @@ -159,30 +24,7 @@ ControllerMixin.reopen({
controllerFor(controllerName) {
Ember.deprecate('Controller#controllerFor is deprecated, please use Ember.inject.controller() instead');
return controllerFor(get(this, 'container'), controllerName);
},

/**
Stores the instances of other controllers available from within
this controller. Any controller listed by name in the `needs`
property will be accessible by name through this property.
```javascript
App.CommentsController = Ember.Controller.extend({
needs: ['post'],
postTitle: function() {
var currentPost = this.get('controllers.post'); // instance of App.PostController
return currentPost.get('title');
}.property('controllers.post.title')
});
```
@see {Ember.ControllerMixin#needs}
@deprecated Use `Ember.inject.controller()` instead.
@property {Object} controllers
@default null
@public
*/
controllers: defaultControllersComputedProperty
}
});

export default ControllerMixin;
176 changes: 0 additions & 176 deletions packages/ember-application/tests/system/controller_test.js

This file was deleted.

0 comments on commit 871cbd6

Please sign in to comment.