Skip to content

Commit

Permalink
[BUGFIX release] Make {{hash}} object properties settables
Browse files Browse the repository at this point in the history
Makes all {{hash}} object properties settable, but deprecates setting
them.

(cherry picked from commit ec4c034)
  • Loading branch information
Chris Garrett committed May 24, 2021
1 parent f740f15 commit 6861e10
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 140 deletions.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@babel/plugin-transform-block-scoping": "^7.8.3",
"@babel/plugin-transform-object-assign": "^7.8.3",
"@ember/edition-utils": "^1.2.0",
"@glimmer/vm-babel-plugins": "0.79.1",
"@glimmer/vm-babel-plugins": "0.79.2",
"babel-plugin-debug-macros": "^0.3.3",
"babel-plugin-filter-imports": "^4.0.0",
"broccoli-concat": "^4.2.4",
Expand All @@ -75,19 +75,19 @@
},
"devDependencies": {
"@babel/preset-env": "^7.9.5",
"@glimmer/compiler": "0.79.1",
"@glimmer/destroyable": "0.79.1",
"@glimmer/compiler": "0.79.2",
"@glimmer/destroyable": "0.79.2",
"@glimmer/env": "^0.1.7",
"@glimmer/global-context": "0.79.1",
"@glimmer/interfaces": "0.79.1",
"@glimmer/manager": "0.79.1",
"@glimmer/node": "0.79.1",
"@glimmer/opcode-compiler": "0.79.1",
"@glimmer/owner": "0.79.1",
"@glimmer/program": "0.79.1",
"@glimmer/reference": "0.79.1",
"@glimmer/runtime": "0.79.1",
"@glimmer/validator": "0.79.1",
"@glimmer/global-context": "0.79.2",
"@glimmer/interfaces": "0.79.2",
"@glimmer/manager": "0.79.2",
"@glimmer/node": "0.79.2",
"@glimmer/opcode-compiler": "0.79.2",
"@glimmer/owner": "0.79.2",
"@glimmer/program": "0.79.2",
"@glimmer/reference": "0.79.2",
"@glimmer/runtime": "0.79.2",
"@glimmer/validator": "0.79.2",
"@simple-dom/document": "^1.4.0",
"@types/qunit": "^2.9.1",
"@types/rsvp": "^4.0.3",
Expand Down
8 changes: 8 additions & 0 deletions packages/@ember/-internals/glimmer/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ const VM_DEPRECATION_OVERRIDES: (DeprecationOptions & {
enabled: '3.27.0',
},
},
{
id: 'setting-on-hash',
until: '4.4.0',
for: 'ember-source',
since: {
enabled: '3.28.0',
},
},
];

const VM_ASSERTION_OVERRIDES: { id: string; message: string }[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { RenderingTestCase, moduleFor, runTask } from 'internal-test-helpers';

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

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

moduleFor(
'Helpers test: {{hash}}',
Expand Down Expand Up @@ -186,5 +187,78 @@ moduleFor(

this.assertText('Chad Hietala');
}

['@test works with computeds']() {
let FooBarComponent = Component.extend({
fullName: computed('hash.firstName', 'hash.lastName', function () {
return `${this.hash.firstName} ${this.hash.lastName}`;
}),
});

this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: `{{this.fullName}}`,
});

this.render(`{{foo-bar hash=(hash firstName=this.firstName lastName=this.lastName)}}`, {
firstName: 'Chad',
lastName: 'Hietala',
});

this.assertText('Chad Hietala');

runTask(() => this.rerender());

this.assertText('Chad Hietala');

runTask(() => {
set(this.context, 'firstName', 'Godfrey');
set(this.context, 'lastName', 'Chan');
});

this.assertText('Godfrey Chan');
}

['@test works when properties are set dynamically']() {
let fooBarInstance;
let FooBarComponent = Component.extend({
init() {
this._super();
fooBarInstance = this;
},
});

this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: `{{this.hash.firstName}} {{this.hash.lastName}}`,
});

this.render(`{{foo-bar hash=(hash firstName=this.firstName)}}`, {
firstName: 'Chad',
});

this.assertText('Chad ');

runTask(() => {
if (HAS_NATIVE_PROXY) {
expectDeprecation(() => {
set(fooBarInstance.hash, 'lastName', 'Hietala');
}, /You set the '.*' property on a {{hash}} object/);
} else {
set(fooBarInstance.hash, 'lastName', 'Hietala');
}
});

this.assertText('Chad Hietala');

runTask(() => {
expectDeprecation(() => {
set(fooBarInstance.hash, 'firstName', 'Godfrey');
set(fooBarInstance.hash, 'lastName', 'Chan');
}, /You set the '.*' property on a {{hash}} object/);
});

this.assertText('Godfrey Chan');
}
}
);
Loading

0 comments on commit 6861e10

Please sign in to comment.