Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecation for Route#render method #19442

Merged
merged 2 commits into from Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -222,10 +222,13 @@ if (ENV._DEBUG_RENDER_TREE) {
}

renderTemplate(_: Controller, { showHeader }: Model): void {
this.render();
expectDeprecation(() => this.render(), 'Usage of `render` is deprecated.');

if (showHeader) {
this.render('header', { outlet: 'header' });
expectDeprecation(
() => this.render('header', { outlet: 'header' }),
'Usage of `render` is deprecated.'
);
} else {
expectDeprecation(
() => this.disconnectOutlet('header'),
Expand Down
Expand Up @@ -464,11 +464,13 @@ moduleFor(
'route:application',
Route.extend({
renderTemplate() {
this.render();
this.render('nav', {
into: 'application',
outlet: 'nav',
});
expectDeprecation(() => {
this.render();
this.render('nav', {
into: 'application',
outlet: 'nav',
});
}, 'Usage of `render` is deprecated.');
},
})
);
Expand Down Expand Up @@ -613,7 +615,10 @@ moduleFor(
},

renderTemplate(controller, model) {
this.render({ controller: model.color, model });
expectDeprecation(
() => this.render({ controller: model.color, model }),
'Usage of `render` is deprecated.'
);
},
})
);
Expand Down Expand Up @@ -659,7 +664,10 @@ moduleFor(
},

renderTemplate(controller, model) {
this.render('common', { controller: 'common', model });
expectDeprecation(
() => this.render('common', { controller: 'common', model }),
'Usage of `render` is deprecated.'
);
},
})
);
Expand All @@ -672,7 +680,10 @@ moduleFor(
},

renderTemplate(controller, model) {
this.render('common', { controller: 'common', model });
expectDeprecation(
() => this.render('common', { controller: 'common', model }),
'Usage of `render` is deprecated.'
);
},
})
);
Expand Down
38 changes: 34 additions & 4 deletions packages/@ember/-internals/routing/lib/system/route.ts
Expand Up @@ -1485,6 +1485,29 @@ class Route extends EmberObject implements IRoute {
return route && route.currentModel;
}

/**
`_render` is used to render a template into a region of another template
(indicated by an `{{outlet}}`).

@method _render
@param {String} name the name of the template to render
@param {Object} [options] the options
@param {String} [options.into] the template to render into,
referenced by name. Defaults to the parent template
@param {String} [options.outlet] the outlet inside `options.into` to render into.
Defaults to 'main'
@param {String|Object} [options.controller] the controller to use for this template,
referenced by name or as a controller instance. Defaults to the Route's paired controller
@param {Object} [options.model] the model object to set on `options.controller`.
Defaults to the return value of the Route's model hook
@private
*/
_render(name?: string, options?: PartialRenderOptions) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactors render to be _render, and call that from within renderTemplate and render instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the symbol utility method from @ember/-internals/utils to make something more truly private.

let renderOptions = buildRenderOptions(this, name, options);
ROUTE_CONNECTIONS.get(this).push(renderOptions);
once(this._router, '_setOutlets');
}

/**
A hook you can use to render the template for the current route.

Expand Down Expand Up @@ -1521,7 +1544,7 @@ class Route extends EmberObject implements IRoute {
*/
renderTemplate(_controller: any, _model: {}) {
// eslint-disable-line no-unused-vars
this.render();
this._render();
}

/**
Expand Down Expand Up @@ -1652,9 +1675,16 @@ class Route extends EmberObject implements IRoute {
@public
*/
render(name?: string, options?: PartialRenderOptions) {
let renderOptions = buildRenderOptions(this, name, options);
ROUTE_CONNECTIONS.get(this).push(renderOptions);
once(this._router, '_setOutlets');
deprecate('Usage of `render` is deprecated.', false, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets include some more information in the deprecation message. I'm thinking this.routeName at least...

id: 'route-render-template',
until: '4.0.0',
url: 'https://deprecations.emberjs.com/v3.x/#toc_route-render-template',
for: 'ember-source',
since: {
enabled: '3.27.0',
},
});
this._render(name, options);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/ember/tests/routing/model_loading_test.js
Expand Up @@ -214,7 +214,10 @@ moduleFor(
Route.extend({
controllerName: 'myController',
renderTemplate() {
this.render('alternative_home');
expectDeprecation(
() => this.render('alternative_home'),
'Usage of `render` is deprecated.'
);
},
})
);
Expand Down