Skip to content

Commit

Permalink
Merge pull request #19346 from emberjs/deprecate-with
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Jan 20, 2021
2 parents ce0b37a + 446267c commit 8c4504e
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 80 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 @@ -112,6 +112,7 @@
@for Ember.Templates.helpers
@param {Object} options
@return {String} HTML string
@deprecated Use '{{#let}}' instead
@public
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,9 @@ moduleFor(
this.registerComponent('foo-bar', { template: 'hello' });

this.render(strip`
{{#with (component 'foo-bar') as |Other|}}
{{#let (component 'foo-bar') as |Other|}}
<Other />
{{/with}}
{{/let}}
`);

this.assertComponentElement(this.firstChild, { content: 'hello' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ moduleFor(

this.render(
strip`
{{#with (hash comp=(component "-looked-up" greeting=this.model.greeting)) as |my|}}
{{#let (hash comp=(component "-looked-up" greeting=this.model.greeting)) as |my|}}
{{#my.comp}}{{/my.comp}}
{{/with}}`,
{{/let}}`,
{
model: {
greeting: 'Hodi',
Expand Down Expand Up @@ -340,11 +340,11 @@ moduleFor(

this.render(
strip`
{{#with (component "-looked-up" greeting="Hola" name="Dolores" age=33) as |first|}}
{{#with (component first greeting="Hej" name="Sigmundur") as |second|}}
{{#let (component "-looked-up" greeting="Hola" name="Dolores" age=33) as |first|}}
{{#let (component first greeting="Hej" name="Sigmundur") as |second|}}
{{component second greeting=this.model.greeting}}
{{/with}}
{{/with}}`,
{{/let}}
{{/let}}`,
{
model: {
greeting: 'Hodi',
Expand Down Expand Up @@ -616,9 +616,9 @@ moduleFor(
});

this.render(strip`
{{#with (hash lookedup=(component "-looked-up")) as |object|}}
{{#let (hash lookedup=(component "-looked-up")) as |object|}}
{{object.lookedup}}
{{/with}}`);
{{/let}}`);

this.assertText(expectedText);

Expand All @@ -635,9 +635,9 @@ moduleFor(

this.render(
strip`
{{#with (hash lookedup=(component "-looked-up")) as |object|}}
{{#let (hash lookedup=(component "-looked-up")) as |object|}}
{{object.lookedup expectedText=this.model.expectedText}}
{{/with}}`,
{{/let}}`,
{
model: {
expectedText,
Expand Down Expand Up @@ -668,9 +668,9 @@ moduleFor(

this.render(
strip`
{{#with (hash lookedup=(component "-looked-up" expectedText=this.model.expectedText)) as |object|}}
{{#let (hash lookedup=(component "-looked-up" expectedText=this.model.expectedText)) as |object|}}
{{object.lookedup}}
{{/with}}`,
{{/let}}`,
{
model: {
expectedText,
Expand Down Expand Up @@ -705,9 +705,9 @@ moduleFor(

this.render(
strip`
{{#with (hash lookedup=(component "-looked-up")) as |object|}}
{{#let (hash lookedup=(component "-looked-up")) as |object|}}
{{object.lookedup this.model.expectedText "Hola"}}
{{/with}}`,
{{/let}}`,
{
model: {
expectedText,
Expand Down Expand Up @@ -748,9 +748,9 @@ moduleFor(

this.render(
strip`
{{#with (hash my-component=(component 'my-component' first)) as |c|}}
{{#let (hash my-component=(component 'my-component' first)) as |c|}}
{{c.my-component}}
{{/with}}`,
{{/let}}`,
{ first: 'first' }
);

Expand Down Expand Up @@ -946,9 +946,9 @@ moduleFor(

this.render(
strip`
{{#with (hash ctxCmp=(component "my-comp" isOpen=isOpen)) as |thing|}}
{{#let (hash ctxCmp=(component "my-comp" isOpen=isOpen)) as |thing|}}
{{#thing.ctxCmp}}This is a contextual component{{/thing.ctxCmp}}
{{/with}}
{{/let}}
`,
{
isOpen: true,
Expand Down Expand Up @@ -1010,9 +1010,9 @@ moduleFor(

this.render(
strip`
{{#with (hash ctxCmp=(component compName isOpen=isOpen)) as |thing|}}
{{#let (hash ctxCmp=(component compName isOpen=isOpen)) as |thing|}}
{{#thing.ctxCmp}}This is a contextual component{{/thing.ctxCmp}}
{{/with}}
{{/let}}
`,
{
compName: 'my-comp',
Expand Down Expand Up @@ -1088,9 +1088,9 @@ moduleFor(

this.render(
strip`
{{#with (hash ctxCmp=(component compName isOpen=isOpen)) as |thing|}}
{{#let (hash ctxCmp=(component compName isOpen=isOpen)) as |thing|}}
{{#thing.ctxCmp}}This is a contextual component{{/thing.ctxCmp}}
{{/with}}
{{/let}}
`,
{
compName: 'my-comp',
Expand Down Expand Up @@ -1198,7 +1198,7 @@ moduleFor(
});

this.render(
'{{#with (hash link=(component "my-link")) as |c|}}{{c.link params=allParams}}{{/with}}',
'{{#let (hash link=(component "my-link")) as |c|}}{{c.link params=allParams}}{{/let}}',
{
allParams: emberA(['a', 'b']),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ moduleFor(
class extends RenderingTestCase {
['@test returns an array']() {
this.render(strip`
{{#with (array "Sergio") as |people|}}
{{#let (array "Sergio") as |people|}}
{{#each people as |personName|}}
{{personName}}
{{/each}}
{{/with}}`);
{{/let}}`);

this.assertText('Sergio');

Expand All @@ -22,11 +22,11 @@ moduleFor(

['@test can have more than one value']() {
this.render(strip`
{{#with (array "Sergio" "Robert") as |people|}}
{{#let (array "Sergio" "Robert") as |people|}}
{{#each people as |personName|}}
{{personName}},
{{/each}}
{{/with}}`);
{{/let}}`);

this.assertText('Sergio,Robert,');

Expand All @@ -35,11 +35,11 @@ moduleFor(

['@test binds values when variables are used']() {
this.render(
strip`{{#with (array personOne) as |people|}}
strip`{{#let (array personOne) as |people|}}
{{#each people as |personName|}}
{{personName}}
{{/each}}
{{/with}}`,
{{/let}}`,
{
personOne: 'Tom',
}
Expand All @@ -58,11 +58,11 @@ moduleFor(

['@test binds multiple values when variables are used']() {
this.render(
strip`{{#with (array personOne personTwo) as |people|}}
strip`{{#let (array personOne personTwo) as |people|}}
{{#each people as |personName|}}
{{personName}},
{{/each}}
{{/with}}`,
{{/let}}`,
{
personOne: 'Tom',
personTwo: 'Yehuda',
Expand Down Expand Up @@ -91,14 +91,14 @@ moduleFor(

['@test array helpers can be nested']() {
this.render(
strip`{{#with (array (array personOne personTwo)) as |listOfPeople|}}
strip`{{#let (array (array personOne personTwo)) as |listOfPeople|}}
{{#each listOfPeople as |people|}}
List:
{{#each people as |personName|}}
{{personName}},
{{/each}}
{{/each}}
{{/with}}`,
{{/let}}`,
{
personOne: 'Tom',
personTwo: 'Yehuda',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ moduleFor(
this.assert.equal(editHandlerWasCalled, true, 'the event handler was called');
}

['@test it should work properly in a {{#with foo as |bar|}} block']() {
['@test it should work properly in a {{#let foo as |bar|}} block']() {
let editHandlerWasCalled = false;

let ExampleComponent = Component.extend({
Expand All @@ -792,7 +792,7 @@ moduleFor(
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template:
'{{#with something as |somethingElse|}}<a href="#" {{action "edit"}}>click me</a>{{/with}}',
'{{#let something as |somethingElse|}}<a href="#" {{action "edit"}}>click me</a>{{/let}}',
});

this.render('{{example-component}}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ moduleFor(
'Helpers test: {{hash}}',
class extends RenderingTestCase {
['@test returns a hash with the right key-value']() {
this.render(`{{#with (hash name="Sergio") as |person|}}{{person.name}}{{/with}}`);
this.render(`{{#let (hash name="Sergio") as |person|}}{{person.name}}{{/let}}`);

this.assertText('Sergio');

Expand All @@ -19,7 +19,7 @@ moduleFor(

['@test can have more than one key-value']() {
this.render(
`{{#with (hash name="Sergio" lastName="Arbeo") as |person|}}{{person.name}} {{person.lastName}}{{/with}}`
`{{#let (hash name="Sergio" lastName="Arbeo") as |person|}}{{person.name}} {{person.lastName}}{{/let}}`
);

this.assertText('Sergio Arbeo');
Expand All @@ -31,7 +31,7 @@ moduleFor(

['@test binds values when variables are used']() {
this.render(
`{{#with (hash name=this.model.firstName lastName="Arbeo") as |person|}}{{person.name}} {{person.lastName}}{{/with}}`,
`{{#let (hash name=this.model.firstName lastName="Arbeo") as |person|}}{{person.name}} {{person.lastName}}{{/let}}`,
{
model: {
firstName: 'Marisa',
Expand All @@ -56,7 +56,7 @@ moduleFor(

['@test binds multiple values when variables are used']() {
this.render(
`{{#with (hash name=this.model.firstName lastName=this.model.lastName) as |person|}}{{person.name}} {{person.lastName}}{{/with}}`,
`{{#let (hash name=this.model.firstName lastName=this.model.lastName) as |person|}}{{person.name}} {{person.lastName}}{{/let}}`,
{
model: {
firstName: 'Marisa',
Expand Down Expand Up @@ -91,7 +91,7 @@ moduleFor(

['@test hash helpers can be nested']() {
this.render(
`{{#with (hash person=(hash name=this.model.firstName)) as |ctx|}}{{ctx.person.name}}{{/with}}`,
`{{#let (hash person=(hash name=this.model.firstName)) as |ctx|}}{{ctx.person.name}}{{/let}}`,
{
model: { firstName: 'Balint' },
}
Expand Down
Loading

0 comments on commit 8c4504e

Please sign in to comment.