Skip to content

Commit 6861e10

Browse files
author
Chris Garrett
committed
[BUGFIX release] Make {{hash}} object properties settables
Makes all {{hash}} object properties settable, but deprecates setting them. (cherry picked from commit ec4c034)
1 parent f740f15 commit 6861e10

File tree

4 files changed

+222
-140
lines changed

4 files changed

+222
-140
lines changed

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@babel/plugin-transform-block-scoping": "^7.8.3",
5252
"@babel/plugin-transform-object-assign": "^7.8.3",
5353
"@ember/edition-utils": "^1.2.0",
54-
"@glimmer/vm-babel-plugins": "0.79.1",
54+
"@glimmer/vm-babel-plugins": "0.79.2",
5555
"babel-plugin-debug-macros": "^0.3.3",
5656
"babel-plugin-filter-imports": "^4.0.0",
5757
"broccoli-concat": "^4.2.4",
@@ -75,19 +75,19 @@
7575
},
7676
"devDependencies": {
7777
"@babel/preset-env": "^7.9.5",
78-
"@glimmer/compiler": "0.79.1",
79-
"@glimmer/destroyable": "0.79.1",
78+
"@glimmer/compiler": "0.79.2",
79+
"@glimmer/destroyable": "0.79.2",
8080
"@glimmer/env": "^0.1.7",
81-
"@glimmer/global-context": "0.79.1",
82-
"@glimmer/interfaces": "0.79.1",
83-
"@glimmer/manager": "0.79.1",
84-
"@glimmer/node": "0.79.1",
85-
"@glimmer/opcode-compiler": "0.79.1",
86-
"@glimmer/owner": "0.79.1",
87-
"@glimmer/program": "0.79.1",
88-
"@glimmer/reference": "0.79.1",
89-
"@glimmer/runtime": "0.79.1",
90-
"@glimmer/validator": "0.79.1",
81+
"@glimmer/global-context": "0.79.2",
82+
"@glimmer/interfaces": "0.79.2",
83+
"@glimmer/manager": "0.79.2",
84+
"@glimmer/node": "0.79.2",
85+
"@glimmer/opcode-compiler": "0.79.2",
86+
"@glimmer/owner": "0.79.2",
87+
"@glimmer/program": "0.79.2",
88+
"@glimmer/reference": "0.79.2",
89+
"@glimmer/runtime": "0.79.2",
90+
"@glimmer/validator": "0.79.2",
9191
"@simple-dom/document": "^1.4.0",
9292
"@types/qunit": "^2.9.1",
9393
"@types/rsvp": "^4.0.3",

packages/@ember/-internals/glimmer/lib/environment.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ const VM_DEPRECATION_OVERRIDES: (DeprecationOptions & {
125125
enabled: '3.27.0',
126126
},
127127
},
128+
{
129+
id: 'setting-on-hash',
130+
until: '4.4.0',
131+
for: 'ember-source',
132+
since: {
133+
enabled: '3.28.0',
134+
},
135+
},
128136
];
129137

130138
const VM_ASSERTION_OVERRIDES: { id: string; message: string }[] = [];

packages/@ember/-internals/glimmer/tests/integration/helpers/hash-test.js

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { RenderingTestCase, moduleFor, runTask } from 'internal-test-helpers';
22

33
import { Component } from '../../utils/helpers';
44

5-
import { set } from '@ember/-internals/metal';
5+
import { set, computed } from '@ember/-internals/metal';
6+
import { HAS_NATIVE_PROXY } from '@ember/-internals/utils';
67

78
moduleFor(
89
'Helpers test: {{hash}}',
@@ -186,5 +187,78 @@ moduleFor(
186187

187188
this.assertText('Chad Hietala');
188189
}
190+
191+
['@test works with computeds']() {
192+
let FooBarComponent = Component.extend({
193+
fullName: computed('hash.firstName', 'hash.lastName', function () {
194+
return `${this.hash.firstName} ${this.hash.lastName}`;
195+
}),
196+
});
197+
198+
this.registerComponent('foo-bar', {
199+
ComponentClass: FooBarComponent,
200+
template: `{{this.fullName}}`,
201+
});
202+
203+
this.render(`{{foo-bar hash=(hash firstName=this.firstName lastName=this.lastName)}}`, {
204+
firstName: 'Chad',
205+
lastName: 'Hietala',
206+
});
207+
208+
this.assertText('Chad Hietala');
209+
210+
runTask(() => this.rerender());
211+
212+
this.assertText('Chad Hietala');
213+
214+
runTask(() => {
215+
set(this.context, 'firstName', 'Godfrey');
216+
set(this.context, 'lastName', 'Chan');
217+
});
218+
219+
this.assertText('Godfrey Chan');
220+
}
221+
222+
['@test works when properties are set dynamically']() {
223+
let fooBarInstance;
224+
let FooBarComponent = Component.extend({
225+
init() {
226+
this._super();
227+
fooBarInstance = this;
228+
},
229+
});
230+
231+
this.registerComponent('foo-bar', {
232+
ComponentClass: FooBarComponent,
233+
template: `{{this.hash.firstName}} {{this.hash.lastName}}`,
234+
});
235+
236+
this.render(`{{foo-bar hash=(hash firstName=this.firstName)}}`, {
237+
firstName: 'Chad',
238+
});
239+
240+
this.assertText('Chad ');
241+
242+
runTask(() => {
243+
if (HAS_NATIVE_PROXY) {
244+
expectDeprecation(() => {
245+
set(fooBarInstance.hash, 'lastName', 'Hietala');
246+
}, /You set the '.*' property on a {{hash}} object/);
247+
} else {
248+
set(fooBarInstance.hash, 'lastName', 'Hietala');
249+
}
250+
});
251+
252+
this.assertText('Chad Hietala');
253+
254+
runTask(() => {
255+
expectDeprecation(() => {
256+
set(fooBarInstance.hash, 'firstName', 'Godfrey');
257+
set(fooBarInstance.hash, 'lastName', 'Chan');
258+
}, /You set the '.*' property on a {{hash}} object/);
259+
});
260+
261+
this.assertText('Godfrey Chan');
262+
}
189263
}
190264
);

0 commit comments

Comments
 (0)