Skip to content

Commit

Permalink
Merge pull request #11484 from cibernox/remove_array_controller
Browse files Browse the repository at this point in the history
[CLEANUP beta] Remove array controller
  • Loading branch information
rwjblue committed Jul 12, 2015
2 parents 5146427 + 0272681 commit 5574f19
Show file tree
Hide file tree
Showing 33 changed files with 43 additions and 1,949 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 @@ -84,7 +84,7 @@ ControllerMixin.reopen({
For example, when you define a controller:
```javascript
App.CommentsController = Ember.ArrayController.extend({
App.CommentsController = Ember.Controller.extend({
needs: ['post']
});
```
Expand Down Expand Up @@ -165,7 +165,7 @@ ControllerMixin.reopen({
property will be accessible by name through this property.
```javascript
App.CommentsController = Ember.ArrayController.extend({
App.CommentsController = Ember.Controller.extend({
needs: ['post'],
postTitle: function() {
var currentPost = this.get('controllers.post'); // instance of App.PostController
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 ArrayController from 'ember-runtime/controllers/array_controller';
import Renderer from 'ember-metal-views/renderer';
import DOMHelper from 'ember-htmlbars/system/dom-helper';
import SelectView from 'ember-views/views/select';
Expand Down Expand Up @@ -1015,7 +1014,6 @@ Application.reopenClass({
registry.register('application:main', namespace, { instantiate: false });

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

registry.register('renderer:-dom', { create() { return new Renderer(new DOMHelper()); } });

Expand Down
13 changes: 5 additions & 8 deletions packages/ember-application/tests/system/controller_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'ember-application/ext/controller';

import { Registry } from 'ember-runtime/system/container';
import { A } from 'ember-runtime/system/native_array';
import ArrayController, { arrayControllerDeprecation } from 'ember-runtime/controllers/array_controller';
import { computed } from 'ember-metal/computed';

QUnit.module('Controller dependencies');
Expand Down Expand Up @@ -58,26 +57,24 @@ QUnit.test('If a controller specifies an unavailable dependency, it raises', fun
});

QUnit.test('Mixin sets up controllers if there is needs before calling super', function() {
expectDeprecation(arrayControllerDeprecation);
var registry = new Registry();
var container = registry.container();

registry.register('controller:other', ArrayController.extend({
registry.register('controller:other', Controller.extend({
needs: 'posts',
model: computed.alias('controllers.posts')
}));

registry.register('controller:another', ArrayController.extend({
registry.register('controller:another', Controller.extend({
needs: 'posts',
modelBinding: 'controllers.posts'
}));

registry.register('controller:posts', ArrayController.extend());
registry.register('controller:posts', Controller.extend());

container.lookup('controller:posts').set('model', A(['a', 'b', 'c']));

deepEqual(['a', 'b', 'c'], container.lookup('controller:other').toArray());
deepEqual(['a', 'b', 'c'], container.lookup('controller:another').toArray());
deepEqual(['a', 'b', 'c'], container.lookup('controller:other').get('model.model').toArray());
deepEqual(['a', 'b', 'c'], container.lookup('controller:another').get('model.model').toArray());
});

QUnit.test('raises if trying to get a controller that was not pre-defined in `needs`', function() {
Expand Down
8 changes: 4 additions & 4 deletions packages/ember-htmlbars/lib/keywords/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
@submodule ember-htmlbars
*/

import ArrayController from 'ember-runtime/controllers/array_controller';

export default function each(morph, env, scope, params, hash, template, inverse, visitor) {
let getValue = env.hooks.getValue;
let firstParam = params[0] && getValue(params[0]);
let keyword = hash['-legacy-keyword'] && getValue(hash['-legacy-keyword']);

if (firstParam && firstParam instanceof ArrayController) {
/* START: Support of legacy ArrayController. TODO: Remove after 1st 2.0 TLS release */
let firstParam = params[0] && getValue(params[0]);
if (firstParam && firstParam._isArrayController) {
env.hooks.block(morph, env, scope, '-legacy-each-with-controller', params, hash, template, inverse, visitor);
return true;
}
/* END: Support of legacy ArrayController */

if (keyword) {
env.hooks.block(morph, env, scope, '-legacy-each-with-keyword', params, hash, template, inverse, visitor);
Expand Down
202 changes: 0 additions & 202 deletions packages/ember-htmlbars/tests/helpers/each_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import EmberObject from 'ember-runtime/system/object';
import run from 'ember-metal/run_loop';
import EmberView from 'ember-views/views/view';
import LegacyEachView from 'ember-views/views/legacy_each_view';
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 { Registry } from 'ember-runtime/system/container';

import { get } from 'ember-metal/property_get';
import { set } from 'ember-metal/property_set';
import { runAppend, runDestroy } from 'ember-runtime/tests/utils';

Expand Down Expand Up @@ -331,81 +328,6 @@ QUnit.test('it works inside a table element', function() {
runDestroy(tableView);
});

QUnit.test('it supports itemController', function() {
var Controller = EmberController.extend({
controllerName: computed(function() {
return `controller:${this.get('model.name')}`;
})
});

runDestroy(view);

var parentController = {
container: container
};

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

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 Holtcontroller:Annabelle');

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

assertText(view, 'controller:Steve Holtcontroller:Annabelle');

run(function() {
people.pushObject({ name: 'Yehuda Katz' });
});

assertText(view, 'controller:Steve Holtcontroller:Annabellecontroller:Yehuda Katz');

run(function() {
set(view, 'people', A([{ name: 'Trek Glowacki' }, { name: 'Geoffrey Grosenbach' }]));
});

assertText(view, 'controller:Trek Glowackicontroller:Geoffrey Grosenbach');

strictEqual(view.childViews[0].get('_arrayController.target'), parentController, 'the target property of the child controllers are set correctly');
});

QUnit.test('itemController should not affect the DOM structure', function() {
var Controller = EmberController.extend({
name: computed.alias('model.name')
});

runDestroy(view);

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

view = EmberView.create({
container: container,
template: compile(
'<div id="a">{{#each view.people itemController="person" as |person|}}{{person.name}}{{/each}}</div>' +
'<div id="b">{{#each view.people as |person|}}{{person.name}}{{/each}}</div>'
),
people: people
});

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

runAppend(view);

equal(view.$('#a').html(), view.$('#b').html());
});


QUnit.test('it supports {{itemView=}}', function() {
var itemView = EmberView.extend({
template: compile('itemView:{{name}}')
Expand Down Expand Up @@ -715,25 +637,6 @@ QUnit.test('it can move to and from {{else}} properly when the backing array gai
assertHTML(view, 'Nothing');
});

QUnit.test('it works with the controller keyword', function() {
runDestroy(view);

var controller = ArrayController.create({
model: A(['foo', 'bar', 'baz'])
});

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

runAppend(view);

equal(view.$().text(), 'foobarbaz');
});

QUnit.test('views inside #each preserve the new context [DEPRECATED]', function() {
runDestroy(view);

Expand Down Expand Up @@ -875,23 +778,6 @@ function testEachWithItem(moduleName, useBlockParams) {
});
}

QUnit.test('controller is assignable inside an #each', function() {
expectDeprecation(arrayControllerDeprecation);
var controller = ArrayController.create({
model: A([{ name: 'Adam' }, { name: 'Steve' }])
});

view = EmberView.create({
container: container,
controller: controller,
template: templateFor('{{#EACH|this|personController}}{{#view controller=personController}}{{name}}{{/view}}{{/each}}', useBlockParams)
});

runAppend(view);

equal(view.$().text(), 'AdamSteve');
});

QUnit.test('it doesn\'t assert when the morph tags have the same parent', function() {
view = EmberView.create({
controller: A(['Cyril', 'David']),
Expand All @@ -903,94 +789,6 @@ function testEachWithItem(moduleName, useBlockParams) {
ok(true, 'No assertion from valid template');
});

QUnit.test('itemController specified in template with name binding does not change context [DEPRECATED]', function() {
var Controller = EmberController.extend({
controllerName: computed(function() {
return `controller:${this.get('model.name')}`;
})
});

registry = new Registry();
registry.register('view:-legacy-each', LegacyEachView);
container = registry.container();

people = A([{ name: 'Steve Holt' }, { name: 'Annabelle' }]);

var parentController = {
container: container,
people: people,
controllerName: 'controller:parentController'
};

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

var template;
expectDeprecation(function() {
template = templateFor('{{#EACH|people|person|itemController="person"}}{{controllerName}} - {{person.controllerName}} - {{/each}}', useBlockParams);
}, /Using 'itemController' with '{{each}}'/);

view = EmberView.create({
template,
container: container,
controller: parentController
});

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

runAppend(view);

equal(view.$().text(), 'controller:parentController - controller:Steve Holt - controller:parentController - controller:Annabelle - ');

run(function() {
people.pushObject({ name: 'Yehuda Katz' });
});

assertText(view, 'controller:parentController - controller:Steve Holt - controller:parentController - controller:Annabelle - controller:parentController - controller:Yehuda Katz - ');

run(function() {
set(parentController, 'people', A([{ name: 'Trek Glowacki' }, { name: 'Geoffrey Grosenbach' }]));
});

assertText(view, 'controller:parentController - controller:Trek Glowacki - controller:parentController - controller:Geoffrey Grosenbach - ');

strictEqual(view.childViews[0].get('_arrayController.target'), parentController, 'the target property of the child controllers are set correctly');
});

QUnit.test('itemController specified in ArrayController with name binding does not change context', function() {
expectDeprecation(arrayControllerDeprecation);
people = A([{ name: 'Steve Holt' }, { name: 'Annabelle' }]);

var PersonController = EmberController.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',
controllerName: 'controller:people'
});
registry = new Registry();
registry.register('view:-legacy-each', LegacyEachView);
container = registry.container();

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

view = EmberView.create({
container: container,
template: templateFor('{{#EACH|this|person}}{{controllerName}} - {{person.controllerName}} - {{/each}}', useBlockParams),
controller: container.lookup('controller:people')
});


runAppend(view);

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


QUnit.test('locals in stable loops update when the list is updated', function() {
expect(3);

Expand Down
Loading

0 comments on commit 5574f19

Please sign in to comment.