Skip to content

Commit

Permalink
Remove ControllerContentModelAliasDeprecation for deprecatingAlias
Browse files Browse the repository at this point in the history
So, this is kind of a fun one.

From what I can tell, `ControllerContentModelAliasDeprecation` was
introduced, due to Controllers having a `content` property, which
`model` was aliased to.
This was done because `ObjectController` and `ArrayController`
were proxying controllers.

But, in Ember, routes set up the `model` property of its respective
controller.
What this meant is that if someone declared a `content` property
in their controller, `model` would—seemingly unrelated—break,
hence the `ControllerContentModelAliasDeprecation` mixin.

Nowadays it is fine to override `content` because the source of
truth was reverse, and `model` is now the primary property, being
`content` the alias.
It is, then, time to remove the old deprecation and instead
deprecate the alias itself, so that in the future users can define
a `content` property in their controllers if they so desire.

Another API bites the dust.
Here's to removing yet more code in the future, and make Ember
sparkle-clean.
  • Loading branch information
locks committed Aug 1, 2017
1 parent 6569e68 commit 2058272
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 68 deletions.
2 changes: 1 addition & 1 deletion features.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"ember-views.render-double-modify": "2.0.0",
"ember-routing.router-resource": "2.0.0",
"ember-routing.top-level-render-helper": "2.11.0",
"ember-runtime.controller-content": "2.16.0",
"ember-runtime.controller-proxy": "2.0.0",
"ember-runtime.action-handler-_actions": "2.0.0",
"ember-runtime.enumerable-contains": "2.7.0",
"ember-runtime.will-merge-mixin": "2.0.0",
"ember-runtime.frozen-copy": "2.0.0",
"ember-runtime.freezable-init": "2.0.0",
"ember-string-utils.fmt": "2.0.0",
Expand Down
13 changes: 8 additions & 5 deletions packages/ember-runtime/lib/mixins/controller.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Mixin, alias } from 'ember-metal';
import { deprecatingAlias } from '../computed/computed_macros';
import ActionHandler from './action_handler';
import ControllerContentModelAliasDeprecation from './controller_content_model_alias_deprecation';

/**
@class ControllerMixin
@namespace Ember
@uses Ember.ActionHandler
@private
*/
export default Mixin.create(ActionHandler, ControllerContentModelAliasDeprecation, {
export default Mixin.create(ActionHandler, {
/* ducktype as a controller */
isController: true,

Expand Down Expand Up @@ -38,12 +38,15 @@ export default Mixin.create(ActionHandler, ControllerContentModelAliasDeprecatio
@property model
@public
*/
*/
model: null,

/**
@private
*/
content: alias('model')

content: deprecatingAlias('model', {
id: 'ember-runtime.controller.content-alias',
until: '2.17.0',
url: 'https://emberjs.com/deprecations/v2.x/#toc_controller-content-alias'
})
});

This file was deleted.

29 changes: 16 additions & 13 deletions packages/ember-runtime/tests/controllers/controller_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,18 @@ QUnit.module('Controller deprecations');

QUnit.module('Controller Content -> Model Alias');

QUnit.test('`model` is aliased as `content`', function() {
expect(1);
QUnit.test('`content` is a deprecated alias of `model`', function() {
expect(2);
let controller = Controller.extend({
model: 'foo-bar'
}).create();

equal(controller.get('content'), 'foo-bar', 'content is an alias of model');
expectDeprecation(function () {
equal(controller.get('content'), 'foo-bar', 'content is an alias of model');
});
});

QUnit.test('`content` is moved to `model` when `model` is unset', function() {
QUnit.test('`content` is not moved to `model` when `model` is unset', function() {
expect(2);
let controller;

Expand All @@ -121,18 +123,19 @@ QUnit.test('`content` is moved to `model` when `model` is unset', function() {
}).create();
});

equal(controller.get('model'), 'foo-bar', 'model is set properly');
equal(controller.get('content'), 'foo-bar', 'content is set properly');
notEqual(controller.get('model'), 'foo-bar', 'model is set properly');
equal(controller.get('content'), 'foo-bar', 'content is not set properly');
});

QUnit.test('specifying `content` (without `model` specified) results in deprecation', function() {
expect(1);
QUnit.test('specifying `content` (without `model` specified) does not result in deprecation', function() {
expect(2);
expectNoDeprecation();

expectDeprecation(function() {
Controller.extend({
content: 'foo-bar'
}).create();
}, 'Do not specify `content` on a Controller, use `model` instead.');
let controller = Controller.extend({
content: 'foo-bar'
}).create();

equal(get(controller, 'content'), 'foo-bar');
});

QUnit.test('specifying `content` (with `model` specified) does not result in deprecation', function() {
Expand Down

0 comments on commit 2058272

Please sign in to comment.