Skip to content

Commit

Permalink
RFC #449 : Deprecate {{partial}}
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinJoyce committed Oct 25, 2019
1 parent 129d00b commit ff9e96b
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 164 deletions.
1 change: 1 addition & 0 deletions packages/@ember/-internals/glimmer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
@method partial
@for Ember.Templates.helpers
@param {String} partialName The name of the template to render minus the leading underscore.
@deprecated Use a component instead
@public
*/

Expand Down
70 changes: 66 additions & 4 deletions packages/@ember/-internals/glimmer/lib/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { privatize as P } from '@ember/-internals/container';
import { ENV } from '@ember/-internals/environment';
import { Factory, FactoryClass, LookupOptions, Owner } from '@ember/-internals/owner';
import { lookupPartial, OwnedTemplateMeta } from '@ember/-internals/views';
import { OwnedTemplateMeta } from '@ember/-internals/views';
import {
EMBER_GLIMMER_SET_COMPONENT_TEMPLATE,
EMBER_MODULE_UNIFICATION,
} from '@ember/canary-features';
import { isTemplateOnlyComponent } from '@ember/component/template-only';
import { assert } from '@ember/debug';
import { assert, deprecate } from '@ember/debug';
import { PARTIALS } from '@ember/deprecated-features';
import EmberError from '@ember/error';
import { _instrumentStart } from '@ember/instrumentation';
import {
ComponentDefinition,
Expand Down Expand Up @@ -176,6 +178,62 @@ function lookupComponent(owner: Owner, name: string, options: LookupOptions): Op
return lookupComponentPair(owner, name);
}

let lookupPartial: { templateName: string; owner: Owner } | any;
let templateFor: { owner: Owner; underscored: string; name: string } | any;
let parseUnderscoredName: { templateName: string } | any;

if (PARTIALS) {
lookupPartial = function(templateName: string, owner: Owner) {
deprecate(
`The use of \`{{partial}}\` is deprecated, please refactor the "${templateName}" partial to a component`,
false,
{
id: 'ember-views.partial',
until: '4.0.0',
url: 'https://deprecations.emberjs.com/v3.x#toc_ember-views-partial',
}
);

if (templateName === null) {
return;
}

let template = templateFor(owner, parseUnderscoredName(templateName), templateName);

assert(`Unable to find partial with name "${templateName}"`, Boolean(template));

return template;
};

templateFor = function(owner: any, underscored: string, name: string) {
if (PARTIALS) {
if (!name) {
return;
}
assert(`templateNames are not allowed to contain periods: ${name}`, name.indexOf('.') === -1);

if (!owner) {
throw new EmberError(
'Container was not found when looking up a views template. ' +
'This is most likely due to manually instantiating an Ember.View. ' +
'See: http://git.io/EKPpnA'
);
}

return owner.lookup(`template:${underscored}`) || owner.lookup(`template:${name}`);
}
};

parseUnderscoredName = function(templateName: string) {
let nameParts = templateName.split('/');
let lastPart = nameParts[nameParts.length - 1];

nameParts[nameParts.length - 1] = `_${lastPart}`;

return nameParts.join('/');
};
}

interface IBuiltInHelpers {
[name: string]: Helper | undefined;
}
Expand Down Expand Up @@ -306,8 +364,12 @@ export default class RuntimeResolver implements IRuntimeResolver<OwnedTemplateMe
* Called by CompileTimeLookup to lookup partial
*/
lookupPartial(name: string, meta: OwnedTemplateMeta): Option<number> {
let partial = this._lookupPartial(name, meta);
return this.handle(partial);
if (PARTIALS) {
let partial = this._lookupPartial(name, meta);
return this.handle(partial);
} else {
return null;
}
}

// end CompileTimeLookup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ moduleFor(
}

['@test attrs in an engine']() {
expectDeprecation(
`The use of \`{{partial}}\` is deprecated, please refactor the "troll" partial to a component`
);

this.setupEngineWithAttrs([]);

return this.visit('/').then(() => {
Expand Down Expand Up @@ -431,7 +435,11 @@ moduleFor(
}

['@test visit() with partials in routable engine'](assert) {
assert.expect(2);
assert.expect(3);

expectDeprecation(
`The use of \`{{partial}}\` is deprecated, please refactor the "foo" partial to a component`
);

let hooks = [];

Expand All @@ -449,7 +457,11 @@ moduleFor(
}

['@test visit() with partials in non-routable engine'](assert) {
assert.expect(2);
assert.expect(3);

expectDeprecation(
`The use of \`{{partial}}\` is deprecated, please refactor the "foo" partial to a component`
);

let hooks = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,9 @@ moduleFor(
template: '{{partial "partialWithYield"}} - In component',
});

this.render('{{#foo-bar}}hello{{/foo-bar}}');
expectDeprecation(() => {
this.render('{{#foo-bar}}hello{{/foo-bar}}');
}, 'The use of `{{partial}}` is deprecated, please refactor the "partialWithYield" partial to a component');

this.assertComponentElement(this.firstChild, {
content: 'yielded: [hello] - In component',
Expand All @@ -780,7 +782,9 @@ moduleFor(
template: '{{partial "partialWithYield"}} - In component',
});

this.render('{{#foo-bar as |value|}}{{value}}{{/foo-bar}}');
expectDeprecation(() => {
this.render('{{#foo-bar as |value|}}{{value}}{{/foo-bar}}');
}, 'The use of `{{partial}}` is deprecated, please refactor the "partialWithYield" partial to a component');

this.assertComponentElement(this.firstChild, {
content: 'yielded: [hello] - In component',
Expand Down
Loading

0 comments on commit ff9e96b

Please sign in to comment.