Skip to content

Commit

Permalink
Merge pull request #11479 from cibernox/remove_object_controller
Browse files Browse the repository at this point in the history
[CLEANUP beta] Remove ObjectController
  • Loading branch information
stefanpenner committed Jul 11, 2015
2 parents 7a8a46b + 56bb97e commit ab9d96f
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 519 deletions.
4 changes: 2 additions & 2 deletions packages/ember-application/lib/ext/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ ControllerMixin.reopen({
Given that you have a nested controller (nested routes):
```javascript
App.CommentsNewController = Ember.ObjectController.extend({
App.CommentsNewController = Ember.Controller.extend({
});
```
When you define a controller that requires access to a nested one:
```javascript
App.IndexController = Ember.ObjectController.extend({
App.IndexController = Ember.Controller.extend({
needs: ['commentsNew']
});
```
Expand Down
2 changes: 0 additions & 2 deletions packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import DefaultResolver from 'ember-application/system/resolver';
import run from 'ember-metal/run_loop';
import { canInvoke } from 'ember-metal/utils';
import Controller from 'ember-runtime/controllers/controller';
import ObjectController from 'ember-runtime/controllers/object_controller';
import ArrayController from 'ember-runtime/controllers/array_controller';
import Renderer from 'ember-metal-views/renderer';
import DOMHelper from 'ember-htmlbars/system/dom-helper';
Expand Down Expand Up @@ -1016,7 +1015,6 @@ Application.reopenClass({
registry.register('application:main', namespace, { instantiate: false });

registry.register('controller:basic', Controller, { instantiate: false });
registry.register('controller:object', ObjectController, { instantiate: false });
registry.register('controller:array', ArrayController, { instantiate: false });

registry.register('renderer:-dom', { create() { return new Renderer(new DOMHelper()); } });
Expand Down
92 changes: 0 additions & 92 deletions packages/ember-htmlbars/tests/helpers/each_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { computed } from 'ember-metal/computed';
import ArrayController, { arrayControllerDeprecation } from 'ember-runtime/controllers/array_controller';
import { A } from 'ember-runtime/system/native_array';
import EmberController from 'ember-runtime/controllers/controller';
import ObjectController from 'ember-runtime/controllers/object_controller';
import { Registry } from 'ember-runtime/system/container';

import { get } from 'ember-metal/property_get';
Expand Down Expand Up @@ -406,97 +405,6 @@ QUnit.test('itemController should not affect the DOM structure', function() {
equal(view.$('#a').html(), view.$('#b').html());
});

QUnit.test('itemController specified in template gets a parentController property', function() {
// using an ObjectController for this test to verify that parentController does accidentally get set
// on the proxied model.
var Controller = ObjectController.extend({
controllerName: computed(function() {
return 'controller:' + get(this, 'model.name') + ' of ' + get(this, 'parentController.company');
})
});
var parentController = {
container: container,
company: 'Yapp'
};

registry.register('controller:array', ArrayController.extend());
runDestroy(view);

view = EmberView.create({
container: container,
template: compile('{{#each view.people itemController="person"}}{{controllerName}}{{/each}}'),
people: people,
controller: parentController
});

registry.register('controller:person', Controller);

runAppend(view);

equal(view.$().text(), 'controller:Steve Holt of Yappcontroller:Annabelle of Yapp');
});

QUnit.test('itemController specified in ArrayController gets a parentController property', function() {
var PersonController = ObjectController.extend({
controllerName: computed(function() {
return 'controller:' + get(this, 'model.name') + ' of ' + get(this, 'parentController.company');
})
});
var PeopleController = ArrayController.extend({
model: people,
itemController: 'person',
company: 'Yapp'
});

registry.register('controller:people', PeopleController);
registry.register('controller:person', PersonController);
runDestroy(view);

view = EmberView.create({
container: container,
template: compile('{{#each}}{{controllerName}}{{/each}}'),
controller: container.lookup('controller:people')
});


runAppend(view);

equal(view.$().text(), 'controller:Steve Holt of Yappcontroller:Annabelle of Yapp');
});

QUnit.test('itemController\'s parentController property, when the ArrayController has a parentController', function() {
var PersonController = ObjectController.extend({
controllerName: computed(function() {
return 'controller:' + get(this, 'model.name') + ' of ' + get(this, 'parentController.company');
})
});
var PeopleController = ArrayController.extend({
model: people,
itemController: 'person',
parentController: computed(function() {
return this.container.lookup('controller:company');
}),
company: 'Yapp'
});
var CompanyController = EmberController.extend();

registry.register('controller:company', CompanyController);
registry.register('controller:people', PeopleController);
registry.register('controller:person', PersonController);

runDestroy(view);
view = EmberView.create({
container: container,
template: compile('{{#each}}{{controllerName}}{{/each}}'),
controller: container.lookup('controller:people')
});


runAppend(view);

equal(view.$().text(), 'controller:Steve Holt of Yappcontroller:Annabelle of Yapp');
});


QUnit.test('it supports {{itemView=}}', function() {
var itemView = EmberView.extend({
Expand Down
158 changes: 0 additions & 158 deletions packages/ember-htmlbars/tests/helpers/with_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import Ember from 'ember-metal/core';
import EmberView from 'ember-views/views/view';
import run from 'ember-metal/run_loop';
import EmberObject from 'ember-runtime/system/object';
import { computed } from 'ember-metal/computed';
import { set } from 'ember-metal/property_set';
import { get } from 'ember-metal/property_get';
import ObjectController from 'ember-runtime/controllers/object_controller';
import {
objectControllerDeprecation
} from 'ember-runtime/controllers/object_controller';
import EmberController from 'ember-runtime/controllers/controller';
import { Registry } from 'ember-runtime/system/container';
import compile from 'ember-template-compiler/system/compile';
Expand Down Expand Up @@ -227,158 +221,6 @@ QUnit.test('it should support #with this as qux', function() {

QUnit.module('Handlebars {{#with foo}} with defined controller');

QUnit.test('it should wrap context with object controller [DEPRECATED]', function() {
var childController;

var Controller = ObjectController.extend({
init() {
if (childController) { throw new Error('Did not expect controller.init to be invoked twice'); }
childController = this;
this._super();
},
controllerName: computed(function() {
return `controller:${this.get('model.name')} and ${this.get('parentController.name')}`;
}).property('model.name', 'parentController.name')
});

var person = EmberObject.create({ name: 'Steve Holt' });
var registry = new Registry();
var container = registry.container();

var parentController = EmberObject.create({
container: container,
name: 'Bob Loblaw'
});

view = EmberView.create({
container: container,
template: compile('{{#with view.person controller="person"}}{{controllerName}}{{/with}}'),
person: person,
controller: parentController
});

registry.register('controller:person', Controller);

expectDeprecation(objectControllerDeprecation);
expectDeprecation('Using the context switching form of `{{with}}` is deprecated. Please use the block param form (`{{#with bar as |foo|}}`) instead.');

runAppend(view);

equal(view.$().text(), 'controller:Steve Holt and Bob Loblaw');

run(function() {
view.rerender();
});

equal(view.$().text(), 'controller:Steve Holt and Bob Loblaw');

run(function() {
parentController.set('name', 'Carl Weathers');
view.rerender();
});

equal(view.$().text(), 'controller:Steve Holt and Carl Weathers');

run(function() {
person.set('name', 'Gob');
view.rerender();
});

equal(view.$().text(), 'controller:Gob and Carl Weathers');

strictEqual(childController.get('target'), parentController, 'the target property of the child controllers are set correctly');

runDestroy(view);
});

/* requires each
QUnit.test("it should still have access to original parentController within an {{#each}}", function() {
var Controller = ObjectController.extend({
controllerName: computed(function() {
return "controller:"+this.get('model.name') + ' and ' + this.get('parentController.name');
})
});
var people = A([{ name: "Steve Holt" }, { name: "Carl Weathers" }]);
var registry = new Registry();
var container = registry.container();
var parentController = EmberObject.create({
container: container,
name: 'Bob Loblaw',
people: people
});
view = EmberView.create({
container: container,
template: compile('{{#each person in people}}{{#with person controller="person"}}{{controllerName}}{{/with}}{{/each}}'),
controller: parentController
});
registry.register('controller:person', Controller);
runAppend(view);
equal(view.$().text(), "controller:Steve Holt and Bob Loblawcontroller:Carl Weathers and Bob Loblaw");
runDestroy(view);
});
*/

QUnit.test('it should wrap keyword with object controller [DEPRECATED]', function() {
expectDeprecation(objectControllerDeprecation);

var PersonController = ObjectController.extend({
name: computed('model.name', function() {
return get(this, 'model.name').toUpperCase();
})
});

var person = EmberObject.create({ name: 'Steve Holt' });
var registry = new Registry();
var container = registry.container();

var parentController = EmberObject.create({
container: container,
person: person,
name: 'Bob Loblaw'
});

view = EmberView.create({
container: container,
template: compile('{{#with person controller="person" as |steve|}}{{name}} - {{steve.name}}{{/with}}'),
controller: parentController
});

registry.register('controller:person', PersonController);

runAppend(view);

equal(view.$().text(), 'Bob Loblaw - STEVE HOLT');

run(function() {
view.rerender();
});

equal(view.$().text(), 'Bob Loblaw - STEVE HOLT');

run(function() {
parentController.set('name', 'Carl Weathers');
view.rerender();
});

equal(view.$().text(), 'Carl Weathers - STEVE HOLT');

run(function() {
person.set('name', 'Gob');
view.rerender();
});

equal(view.$().text(), 'Carl Weathers - GOB');

runDestroy(view);
});

QUnit.test('destroys the controller generated with {{with foo controller=\'blah\'}} [DEPRECATED]', function() {
var destroyed = false;
var Controller = EmberController.extend({
Expand Down
2 changes: 0 additions & 2 deletions packages/ember-routing-htmlbars/tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {

import Registry from 'container/registry';
import Controller from 'ember-runtime/controllers/controller';
import ObjectController from 'ember-runtime/controllers/object_controller';
import ArrayController from 'ember-runtime/controllers/array_controller';

import EmberView from 'ember-views/views/view';
Expand Down Expand Up @@ -53,7 +52,6 @@ function buildRegistry(namespace) {
registry.register('location:hash', HashLocation);

registry.register('controller:basic', Controller, { instantiate: false });
registry.register('controller:object', ObjectController, { instantiate: false });
registry.register('controller:array', ArrayController, { instantiate: false });

registry.register('view:toplevel', EmberView.extend());
Expand Down
8 changes: 2 additions & 6 deletions packages/ember-routing/lib/system/generate_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import { isArray } from 'ember-runtime/utils';
The type of the generated controller factory is derived
from the context. If the context is an array an array controller
is generated, if an object, an object controller otherwise, a basic
controller is generated.
is generated, otherwise, a basic controller is generated.
You can customize your generated controllers by defining
`App.ObjectController` or `App.ArrayController`.
You can customize your generated controllers by defining `App.ArrayController`.
@for Ember
@method generateControllerFactory
Expand All @@ -28,8 +26,6 @@ export function generateControllerFactory(container, controllerName, context) {

if (context && isArray(context)) {
controllerType = 'array';
} else if (context) {
controllerType = 'object';
} else {
controllerType = 'basic';
}
Expand Down
7 changes: 2 additions & 5 deletions packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -1627,9 +1627,6 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
});
```
This means that your template will get a proxy for the model as its
context, and you can act as though the model itself was the context.
The provided controller will be one resolved based on the name
of this route.
Expand All @@ -1638,7 +1635,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
* if the model is an `Ember.Array` (including record arrays from Ember
Data), the controller is an `Ember.ArrayController`.
* otherwise, the controller is an `Ember.ObjectController`.
* otherwise, the controller is basic `Ember.Controller`.
As an example, consider the router:
Expand All @@ -1649,7 +1646,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, {
```
For the `post` route, a controller named `App.PostController` would
be used if it is defined. If it is not defined, an `Ember.ObjectController`
be used if it is defined. If it is not defined, a basic `Ember.Controller`
instance would be used.
Example
Expand Down
Loading

0 comments on commit ab9d96f

Please sign in to comment.