Skip to content

Commit

Permalink
Use symbol to create private render method
Browse files Browse the repository at this point in the history
  • Loading branch information
patocallaghan committed Mar 2, 2021
1 parent 51d3614 commit dcf0819
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ if (ENV._DEBUG_RENDER_TREE) {
}

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

if (showHeader) {
expectDeprecation(
() => this.render('header', { outlet: 'header' }),
'Usage of `render` is deprecated.'
/Usage of `render` is deprecated/
);
} else {
expectDeprecation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ moduleFor(
into: 'application',
outlet: 'nav',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
})
);
Expand Down Expand Up @@ -617,7 +617,7 @@ moduleFor(
renderTemplate(controller, model) {
expectDeprecation(
() => this.render({ controller: model.color, model }),
'Usage of `render` is deprecated.'
/Usage of `render` is deprecated/
);
},
})
Expand Down Expand Up @@ -666,7 +666,7 @@ moduleFor(
renderTemplate(controller, model) {
expectDeprecation(
() => this.render('common', { controller: 'common', model }),
'Usage of `render` is deprecated.'
/Usage of `render` is deprecated/
);
},
})
Expand All @@ -682,7 +682,7 @@ moduleFor(
renderTemplate(controller, model) {
expectDeprecation(
() => this.render('common', { controller: 'common', model }),
'Usage of `render` is deprecated.'
/Usage of `render` is deprecated/
);
},
})
Expand Down
15 changes: 8 additions & 7 deletions packages/@ember/-internals/routing/lib/system/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
Object as EmberObject,
typeOf,
} from '@ember/-internals/runtime';
import { isProxy, lookupDescriptor } from '@ember/-internals/utils';
import { isProxy, lookupDescriptor, symbol } from '@ember/-internals/utils';
import Controller from '@ember/controller';
import { assert, deprecate, info, isTesting } from '@ember/debug';
import { ROUTER_EVENTS } from '@ember/deprecated-features';
Expand Down Expand Up @@ -49,6 +49,7 @@ import generateController from './generate_controller';
import EmberRouter, { QueryParam } from './router';

export const ROUTE_CONNECTIONS = new WeakMap();
const RENDER = symbol('render') as string;

export function defaultSerialize(
model: {},
Expand Down Expand Up @@ -1486,10 +1487,10 @@ class Route extends EmberObject implements IRoute {
}

/**
`_render` is used to render a template into a region of another template
`this[RENDER]` is used to render a template into a region of another template
(indicated by an `{{outlet}}`).
@method _render
@method this[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,
Expand All @@ -1502,7 +1503,7 @@ class Route extends EmberObject implements IRoute {
Defaults to the return value of the Route's model hook
@private
*/
_render(name?: string, options?: PartialRenderOptions) {
[RENDER](name?: string, options?: PartialRenderOptions) {
let renderOptions = buildRenderOptions(this, name, options);
ROUTE_CONNECTIONS.get(this).push(renderOptions);
once(this._router, '_setOutlets');
Expand Down Expand Up @@ -1544,7 +1545,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 @@ -1675,7 +1676,7 @@ class Route extends EmberObject implements IRoute {
@public
*/
render(name?: string, options?: PartialRenderOptions) {
deprecate('Usage of `render` is deprecated.', false, {
deprecate(`Usage of \`render\` is deprecated. Route: \`${this.routeName}\``, false, {
id: 'route-render-template',
until: '4.0.0',
url: 'https://deprecations.emberjs.com/v3.x/#toc_route-render-template',
Expand All @@ -1684,7 +1685,7 @@ class Route extends EmberObject implements IRoute {
enabled: '3.27.0',
},
});
this._render(name, options);
this[RENDER](name, options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ember/tests/routing/model_loading_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ moduleFor(
renderTemplate() {
expectDeprecation(
() => this.render('alternative_home'),
'Usage of `render` is deprecated.'
/Usage of `render` is deprecated/
);
},
})
Expand Down
61 changes: 29 additions & 32 deletions packages/ember/tests/routing/template_rendering_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ moduleFor(
'route:home',
Route.extend({
renderTemplate() {
expectDeprecation(() => this.render('homepage'), 'Usage of `render` is deprecated.');
expectDeprecation(() => this.render('homepage'), /Usage of `render` is deprecated/);
},
})
);
Expand All @@ -93,7 +93,7 @@ moduleFor(
'route:home',
Route.extend({
renderTemplate() {
expectDeprecation(() => this.render('homepage'), 'Usage of `render` is deprecated.');
expectDeprecation(() => this.render('homepage'), /Usage of `render` is deprecated/);
},
})
);
Expand Down Expand Up @@ -121,7 +121,7 @@ moduleFor(
Route.extend({
controllerName: 'foo',
renderTemplate() {
expectDeprecation(() => this.render('homepage'), 'Usage of `render` is deprecated.');
expectDeprecation(() => this.render('homepage'), /Usage of `render` is deprecated/);
},
})
);
Expand Down Expand Up @@ -161,7 +161,7 @@ moduleFor(
renderTemplate() {
expectDeprecation(
() => this.render({ controller: 'home' }),
'Usage of `render` is deprecated.'
/Usage of `render` is deprecated/
);
},
})
Expand Down Expand Up @@ -202,7 +202,7 @@ moduleFor(
'route:home',
Route.extend({
renderTemplate() {
expectDeprecation(() => this.render('homepage'), 'Usage of `render` is deprecated.');
expectDeprecation(() => this.render('homepage'), /Usage of `render` is deprecated/);
},
})
);
Expand All @@ -226,7 +226,7 @@ moduleFor(
this.render('bio', {
model: { name: 'emberjs' },
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
})
);
Expand Down Expand Up @@ -276,7 +276,7 @@ moduleFor(
into: 'home',
outlet: 'alert',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
},
})
Expand Down Expand Up @@ -306,7 +306,7 @@ moduleFor(
Route.extend({
templateName: 'alert',
renderTemplate() {
expectDeprecation(() => this.render({}), 'Usage of `render` is deprecated.');
expectDeprecation(() => this.render({}), /Usage of `render` is deprecated/);
},
})
);
Expand Down Expand Up @@ -429,7 +429,7 @@ moduleFor(
renderTemplate() {
expectDeprecation(
() => this.render('middle/bottom', { into: 'top' }),
'Usage of `render` is deprecated.'
/Usage of `render` is deprecated/
);
},
})
Expand Down Expand Up @@ -467,7 +467,7 @@ moduleFor(
expectDeprecation(() => {
this.render('person/profile');
this.render('person/details', { into: 'person/profile' });
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
})
);
Expand Down Expand Up @@ -503,7 +503,7 @@ moduleFor(
into: 'application',
outlet: 'menu',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
})
);
Expand Down Expand Up @@ -653,7 +653,7 @@ moduleFor(
renderTemplate() {
expectDeprecation(
() => this.render('shared', { controller: 'shared' }),
'Usage of `render` is deprecated.'
/Usage of `render` is deprecated/
);
},
});
Expand Down Expand Up @@ -736,7 +736,7 @@ moduleFor(
into: 'application',
outlet: 'footer',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
})
);
Expand Down Expand Up @@ -806,7 +806,7 @@ moduleFor(
into: 'application',
outlet: 'modal',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
hideModal() {
expectDeprecation(
Expand All @@ -831,7 +831,7 @@ moduleFor(
this.render('posts/extra', {
into: 'posts/index',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
hideExtra() {
expectDeprecation(
Expand Down Expand Up @@ -940,7 +940,7 @@ moduleFor(
into: 'application',
outlet: 'modal',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
hideModal() {
expectDeprecation(
Expand Down Expand Up @@ -1017,7 +1017,7 @@ moduleFor(
showModal() {
expectDeprecation(
() => this.render('modal', { into: 'posts', outlet: 'modal' }),
'Usage of `render` is deprecated.'
/Usage of `render` is deprecated/
);
},
hideModal() {
Expand All @@ -1041,7 +1041,7 @@ moduleFor(

['@test Specifying non-existent controller name in route#render throws'](assert) {
expectDeprecation('Usage of `renderTemplate` is deprecated.');
expectDeprecation('Usage of `render` is deprecated.');
expectDeprecation(/Usage of `render` is deprecated/);
assert.expect(3);

this.router.map(function () {
Expand Down Expand Up @@ -1109,7 +1109,7 @@ moduleFor(
into: 'application',
outlet: 'other',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
})
);
Expand Down Expand Up @@ -1142,7 +1142,7 @@ moduleFor(
into: 'application',
outlet: 'other',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
actions: {
banish() {
Expand Down Expand Up @@ -1192,7 +1192,7 @@ moduleFor(
into: 'application',
outlet: 'other',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
})
);
Expand Down Expand Up @@ -1220,7 +1220,7 @@ moduleFor(
into: 'application',
outlet: 'other',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
},
})
Expand Down Expand Up @@ -1267,7 +1267,7 @@ moduleFor(
outlet: 'common',
into: 'app',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
})
);
Expand All @@ -1281,7 +1281,7 @@ moduleFor(
outlet: 'sub',
into: 'app',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
})
);
Expand Down Expand Up @@ -1328,7 +1328,7 @@ moduleFor(
into: 'application',
outlet: 'modal',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
close() {
expectDeprecation(
Expand Down Expand Up @@ -1371,10 +1371,7 @@ moduleFor(
'route:root',
Route.extend({
renderTemplate() {
expectDeprecation(
() => this.render('exports/root'),
'Usage of `render` is deprecated.'
);
expectDeprecation(() => this.render('exports/root'), /Usage of `render` is deprecated/);
},
})
);
Expand All @@ -1385,7 +1382,7 @@ moduleFor(
renderTemplate() {
expectDeprecation(
() => this.render('exports/index'),
'Usage of `render` is deprecated.'
/Usage of `render` is deprecated/
);
},
})
Expand Down Expand Up @@ -1414,7 +1411,7 @@ moduleFor(
into: 'application',
outlet: 'modal',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
},
})
Expand Down Expand Up @@ -1536,7 +1533,7 @@ moduleFor(
outlet: undefined,
parentView: 'application',
});
}, 'Usage of `render` is deprecated.');
}, /Usage of `render` is deprecated/);
},
hideModal() {
expectDeprecation(
Expand Down
Loading

0 comments on commit dcf0819

Please sign in to comment.