Skip to content

Commit

Permalink
Deprecate ArrayController. Resolves #11450
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebuilds committed Jun 15, 2015
1 parent 1d170a2 commit af7cd98
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/ember-application/tests/system/controller_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "ember-application/ext/controller";

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

QUnit.module("Controller dependencies");
Expand Down Expand Up @@ -58,6 +58,7 @@ 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();

Expand Down
4 changes: 3 additions & 1 deletion packages/ember-htmlbars/tests/helpers/each_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 from "ember-runtime/controllers/array_controller";
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";
Expand Down Expand Up @@ -968,6 +968,7 @@ 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" }])
});
Expand Down Expand Up @@ -1048,6 +1049,7 @@ function testEachWithItem(moduleName, useBlockParams) {
});

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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import EventDispatcher from "ember-views/system/event_dispatcher";

import { computed } from "ember-metal/computed";
import Namespace from "ember-runtime/system/namespace";
import ArrayController from "ember-runtime/controllers/array_controller";
import ArrayController, { arrayControllerDeprecation } from "ember-runtime/controllers/array_controller";
import ArrayProxy from "ember-runtime/system/array_proxy";
import SelectView from "ember-views/views/select";
import compile from 'ember-template-compiler/system/compile';
Expand All @@ -26,6 +26,7 @@ QUnit.module("ember-htmlbars: Ember.Select - usage inside templates", {
});

QUnit.test("works from a template with bindings [DEPRECATED]", function() {
expectDeprecation(arrayControllerDeprecation);
var Person = EmberObject.extend({
id: null,
firstName: null,
Expand Down Expand Up @@ -88,6 +89,7 @@ QUnit.test("works from a template with bindings [DEPRECATED]", function() {
});

QUnit.test("works from a template", function() {
expectDeprecation(arrayControllerDeprecation);
var Person = EmberObject.extend({
id: null,
firstName: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ActionManager from "ember-views/system/action_manager";
import { Registry } from "ember-runtime/system/container";
import EmberObject from "ember-runtime/system/object";
import EmberController from "ember-runtime/controllers/controller";
import EmberArrayController from "ember-runtime/controllers/array_controller";
import EmberArrayController, { arrayControllerDeprecation } from "ember-runtime/controllers/array_controller";

import compile from "ember-template-compiler/system/compile";
import EmberView from "ember-views/views/view";
Expand Down Expand Up @@ -132,6 +132,7 @@ QUnit.test("Inside a yield, the target points at the original target", function(
});

QUnit.test("should target the current controller inside an {{each}} loop [DEPRECATED]", function() {
expectDeprecation(arrayControllerDeprecation);
var registeredTarget;

ActionHelper.registerAction = function({ node }) {
Expand Down Expand Up @@ -196,6 +197,7 @@ QUnit.test("should target the with-controller inside an {{#with controller='pers
QUnit.skip("should target the with-controller inside an {{each}} in a {{#with controller='person'}} [DEPRECATED]", function() {
expectDeprecation(eachDeprecation);
expectDeprecation('Using the context switching form of `{{with}}` is deprecated. Please use the keyword form (`{{with foo as bar}}`) instead.');
expectDeprecation(arrayControllerDeprecation);

var eventsCalled = [];

Expand Down
4 changes: 3 additions & 1 deletion packages/ember-routing-htmlbars/tests/helpers/render_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { observer } from 'ember-metal/mixin';
import Namespace from "ember-runtime/system/namespace";

import EmberController from "ember-runtime/controllers/controller";
import EmberArrayController from "ember-runtime/controllers/array_controller";
import EmberArrayController, { arrayControllerDeprecation } from "ember-runtime/controllers/array_controller";

import compile from "ember-template-compiler/system/compile";

Expand Down Expand Up @@ -213,6 +213,7 @@ QUnit.test("{{render}} helper should raise an error when a given controller name
});

QUnit.test("{{render}} helper should render with given controller", function() {
expectDeprecation(arrayControllerDeprecation);
var template = '{{render "home" controller="posts"}}';
var controller = EmberController.extend({ container: container });
var id = 0;
Expand Down Expand Up @@ -421,6 +422,7 @@ QUnit.test("{{render}} helper should render templates both with and without mode
});

QUnit.test("{{render}} helper should link child controllers to the parent controller", function() {
expectDeprecation(arrayControllerDeprecation);
var parentTriggered = 0;

var template = '<h1>HI</h1>{{render "posts"}}';
Expand Down
4 changes: 3 additions & 1 deletion packages/ember-routing/tests/system/controller_for_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Namespace from "ember-runtime/system/namespace";
import { classify } from "ember-runtime/system/string";
import Controller from "ember-runtime/controllers/controller";
import ObjectController from "ember-runtime/controllers/object_controller";
import ArrayController from "ember-runtime/controllers/array_controller";
import ArrayController, { arrayControllerDeprecation } from "ember-runtime/controllers/array_controller";
import controllerFor from "ember-routing/system/controller_for";
import generateController from "ember-routing/system/generate_controller";
import {
Expand Down Expand Up @@ -103,6 +103,7 @@ QUnit.test("generateController should create Ember.ObjectController [DEPRECATED]
});

QUnit.test("generateController should create Ember.ArrayController", function() {
expectDeprecation(arrayControllerDeprecation);
var context = Ember.A();
var controller = generateController(container, 'home', context);

Expand Down Expand Up @@ -130,6 +131,7 @@ QUnit.test("generateController should create App.ObjectController if provided",
});

QUnit.test("generateController should create App.ArrayController if provided", function() {
expectDeprecation(arrayControllerDeprecation);
var context = Ember.A();
var controller;
namespace.ArrayController = ArrayController.extend();
Expand Down
4 changes: 4 additions & 0 deletions packages/ember-runtime/lib/controllers/array_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import EmberError from 'ember-metal/error';
import EmberArray from 'ember-runtime/mixins/array';
import replace from 'ember-metal/replace';

export var arrayControllerDeprecation = '`Ember.ArrayController` is deprecated.';

/**
`Ember.ArrayController` provides a way for you to publish a collection of
objects so that you can easily bind to the collection from a Handlebars
Expand Down Expand Up @@ -97,6 +99,7 @@ import replace from 'ember-metal/replace';
@extends Ember.ArrayProxy
@uses Ember.SortableMixin
@uses Ember.ControllerMixin
@deprecated
@public
*/

Expand Down Expand Up @@ -199,6 +202,7 @@ export default ArrayProxy.extend(ControllerMixin, SortableMixin, {
},

init() {
Ember.deprecate(arrayControllerDeprecation);
this._super(...arguments);
this._subControllers = [];
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ember from 'ember-metal/core';
import MutableArrayTests from 'ember-runtime/tests/suites/mutable_array';
import ArrayController from "ember-runtime/controllers/array_controller";
import ArrayController, { arrayControllerDeprecation } from "ember-runtime/controllers/array_controller";
import { set } from 'ember-metal/property_set';
import { get } from 'ember-metal/property_get';

Expand All @@ -11,6 +11,7 @@ MutableArrayTests.extend({

newObject(ary) {
var ret = ary ? ary.slice() : this.newFixture(3);
expectDeprecation(arrayControllerDeprecation);
return ArrayController.create({
model: Ember.A(ret)
});
Expand All @@ -28,19 +29,22 @@ MutableArrayTests.extend({
QUnit.module("ember-runtime: array_controller");

QUnit.test("defaults its `model` to an empty array", function () {
expectDeprecation(arrayControllerDeprecation);
var Controller = ArrayController.extend();
deepEqual(Controller.create().get("model"), [], "`ArrayController` defaults its model to an empty array");
equal(Controller.create().get('firstObject'), undefined, 'can fetch firstObject');
equal(Controller.create().get('lastObject'), undefined, 'can fetch lastObject');
});

QUnit.test("Ember.ArrayController length property works even if model was not set initially", function() {
expectDeprecation(arrayControllerDeprecation);
var controller = ArrayController.create();
controller.pushObject('item');
equal(controller.get('length'), 1);
});

QUnit.test('works properly when model is set to an Ember.A()', function() {
expectDeprecation(arrayControllerDeprecation);
var controller = ArrayController.create();

set(controller, 'model', Ember.A(['red', 'green']));
Expand All @@ -49,6 +53,7 @@ QUnit.test('works properly when model is set to an Ember.A()', function() {
});

QUnit.test('works properly when model is set to a plain array', function() {
expectDeprecation(arrayControllerDeprecation);
var controller = ArrayController.create();

if (Ember.EXTEND_PROTOTYPES) {
Expand All @@ -63,6 +68,7 @@ QUnit.test('works properly when model is set to a plain array', function() {
});

QUnit.test('works properly when model is set to `null`', function() {
expectDeprecation(arrayControllerDeprecation);
var controller = ArrayController.create();

set(controller, 'model', null);
Expand Down
3 changes: 2 additions & 1 deletion packages/ember-runtime/tests/controllers/controller_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Controller from "ember-runtime/controllers/controller";
import Service from "ember-runtime/system/service";
import ObjectController from "ember-runtime/controllers/object_controller";
import ArrayController from "ember-runtime/controllers/array_controller";
import ArrayController, { arrayControllerDeprecation } from "ember-runtime/controllers/array_controller";
import {
objectControllerDeprecation
} from "ember-runtime/controllers/object_controller";
Expand Down Expand Up @@ -243,6 +243,7 @@ QUnit.test("controllers can be injected into ObjectControllers", function() {
});

QUnit.test("controllers can be injected into ArrayControllers", function() {
expectDeprecation(arrayControllerDeprecation);
var registry = new Registry();
var container = registry.container();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {get} from "ember-metal/property_get";
import {computed} from "ember-metal/computed";
import compare from "ember-runtime/compare";
import EmberObject from "ember-runtime/system/object";
import ArrayController from "ember-runtime/controllers/array_controller";
import ArrayController, { arrayControllerDeprecation } from "ember-runtime/controllers/array_controller";
import Controller from "ember-runtime/controllers/controller";
import {sort} from "ember-runtime/computed/reduce_computed_macros";
import Registry from "container/registry";
Expand Down Expand Up @@ -54,13 +54,15 @@ QUnit.module("Ember.ArrayController - itemController", {
});

function createUnwrappedArrayController() {
expectDeprecation(arrayControllerDeprecation);
arrayController = ArrayController.create({
container: container,
model: lannisters
});
}

function createArrayController() {
expectDeprecation(arrayControllerDeprecation);
arrayController = ArrayController.create({
container: container,
itemController: 'Item',
Expand All @@ -69,6 +71,7 @@ function createArrayController() {
}

function createDynamicArrayController() {
expectDeprecation(arrayControllerDeprecation);
arrayController = ArrayController.create({
container: container,
lookupItemController(object) {
Expand Down Expand Up @@ -238,6 +241,7 @@ QUnit.test("`itemController` can be dynamic by overwriting `lookupItemController
});

QUnit.test("when `idx` is out of range, `lookupItemController` is not called", function() {
expectDeprecation(arrayControllerDeprecation);
arrayController = ArrayController.create({
container: container,
lookupItemController(object) {
Expand All @@ -251,6 +255,7 @@ QUnit.test("when `idx` is out of range, `lookupItemController` is not called", f
});

QUnit.test("if `lookupItemController` returns a string, it must be resolvable by the container", function() {
expectDeprecation(arrayControllerDeprecation);
arrayController = ArrayController.create({
container: container,
lookupItemController(object) {
Expand All @@ -267,6 +272,7 @@ QUnit.test("if `lookupItemController` returns a string, it must be resolvable by
});

QUnit.test("target and parentController are set to the concrete parentController", function() {
expectDeprecation(arrayControllerDeprecation);
var parent = ArrayController.create({

});
Expand Down
5 changes: 4 additions & 1 deletion packages/ember-runtime/tests/mixins/sortable_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {listenersFor} from "ember-metal/events";
import ArrayProxy from "ember-runtime/system/array_proxy";
import SortableMixin from "ember-runtime/mixins/sortable";
import EmberObject from "ember-runtime/system/object";
import ArrayController from "ember-runtime/controllers/array_controller";
import ArrayController, { arrayControllerDeprecation } from "ember-runtime/controllers/array_controller";

var unsortedArray, sortedArrayController;

Expand Down Expand Up @@ -159,6 +159,7 @@ QUnit.module("Ember.Sortable with content and sortProperties", {

unsortedArray = Ember.A(Ember.A(array).copy());

expectDeprecation(arrayControllerDeprecation);
sortedArrayController = ArrayController.create({
content: unsortedArray,
sortProperties: ['name']
Expand Down Expand Up @@ -281,6 +282,7 @@ QUnit.test("sortProperties observers removed on content removal", function() {
QUnit.module("Ember.Sortable with sortProperties", {
setup() {
run(function() {
expectDeprecation(arrayControllerDeprecation);
sortedArrayController = ArrayController.create({
sortProperties: ['name']
});
Expand Down Expand Up @@ -310,6 +312,7 @@ QUnit.test("you can set content later and it will be sorted", function() {
QUnit.module("Ember.Sortable with sortFunction and sortProperties", {
setup() {
run(function() {
expectDeprecation(arrayControllerDeprecation);
sortedArrayController = ArrayController.create({
sortProperties: ['name'],
sortFunction(v, w) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Ember from "ember-metal/core";
import {set} from "ember-metal/property_set";
import run from "ember-metal/run_loop";
import ArrayProxy from "ember-runtime/system/array_proxy";
import ArrayController from "ember-runtime/controllers/array_controller";
import ArrayController, { arrayControllerDeprecation } from "ember-runtime/controllers/array_controller";

QUnit.module("ArrayProxy - content change");

Expand Down Expand Up @@ -69,6 +69,7 @@ QUnit.test("The `arrangedContentDidChange` method is invoked after `content` is
});

QUnit.test("The ArrayProxy doesn't explode when assigned a destroyed object", function() {
expectDeprecation(arrayControllerDeprecation);
var arrayController = ArrayController.create();
var proxy = ArrayProxy.create();

Expand Down
3 changes: 2 additions & 1 deletion packages/ember-testing/tests/integration_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ember from "ember-metal/core";
import run from "ember-metal/run_loop";
import EmberObject from "ember-runtime/system/object";
import ArrayController from "ember-runtime/controllers/array_controller";
import ArrayController, { arrayControllerDeprecation } from "ember-runtime/controllers/array_controller";
import jQuery from "ember-views/system/jquery";
import EmberView from "ember-views/views/view";
import Test from "ember-testing/test";
Expand Down Expand Up @@ -86,6 +86,7 @@ QUnit.test("template is bound to empty array of people", function() {
});

QUnit.test("template is bound to array of 2 people", function() {
expectDeprecation(arrayControllerDeprecation);
App.Person.find = function() {
var people = Ember.A();
var first = App.Person.create({ firstName: "x" });
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-views/tests/views/collection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import run from "ember-metal/run_loop";
import { Mixin } from "ember-metal/mixin";
import { fmt } from "ember-runtime/system/string";
import ArrayProxy from "ember-runtime/system/array_proxy";
import ArrayController from "ember-runtime/controllers/array_controller";
import ArrayController, { arrayControllerDeprecation } from "ember-runtime/controllers/array_controller";
import jQuery from "ember-views/system/jquery";
import CollectionView from "ember-views/views/collection_view";
import View from "ember-views/views/view";
Expand Down Expand Up @@ -506,7 +506,7 @@ QUnit.test("should not render the emptyView if content is emptied and refilled i
});

QUnit.test("a array_proxy that backs an sorted array_controller that backs a collection view functions properly", function() {

expectDeprecation(arrayControllerDeprecation);
var array = Ember.A([{ name: "Other Katz" }]);
var arrayProxy = ArrayProxy.create({ content: array });

Expand Down
Loading

0 comments on commit af7cd98

Please sign in to comment.