diff --git a/packages/@glimmer-workspace/integration-tests/test/helpers/hash-test.ts b/packages/@glimmer-workspace/integration-tests/test/helpers/hash-test.ts index 1113ac3203..3b498af2b0 100644 --- a/packages/@glimmer-workspace/integration-tests/test/helpers/hash-test.ts +++ b/packages/@glimmer-workspace/integration-tests/test/helpers/hash-test.ts @@ -185,93 +185,6 @@ class HashTest extends RenderTest { this.assertHTML('Godfrey'); this.assertStableRerender(); } - - @test - 'defined hash keys can be updated'(assert: Assert) { - class FooBar extends GlimmerishComponent { - constructor(owner: object, args: { hash: Record }) { - super(owner, args); - args.hash['firstName'] = 'Chad'; - - assert.strictEqual(args.hash['firstName'], 'Chad', 'Name updated in JS'); - } - } - - this.registerComponent('Glimmer', 'FooBar', `{{yield @hash}}`, FooBar); - - this.render( - `{{values.firstName}} {{values.lastName}}` - ); - - // Name will not be updated in templates because templates access the child - // reference on hashes directly - this.assertHTML('Godfrey Hietala'); - this.assertStableRerender(); - - assert.validateDeprecations( - /You set the 'firstName' property on a \{\{hash\}\} object. Setting properties on objects generated by \{\{hash\}\} is deprecated. Please update to use an object created with a tracked property or getter, or with a custom helper./u - ); - } - - @test - 'defined hash keys are reset whenever the upstream changes'(assert: Assert) { - class FooBar extends GlimmerishComponent { - constructor(owner: object, args: { hash: Record }) { - super(owner, args); - args.hash['name'] = 'Chad'; - } - - get alias() { - return (this.args['hash'] as Record)['name']; - } - } - - this.registerComponent('Glimmer', 'FooBar', `{{yield @hash this.alias}}`, FooBar); - - this.render( - `{{values.name}} {{alias}}`, - { - name: 'Godfrey', - } - ); - - // JS alias will be updated, version accessed lazily in templates will not - this.assertHTML('Godfrey Chad'); - this.assertStableRerender(); - - this.rerender({ name: 'Tom' }); - - // Both will be updated to match the new value - this.assertHTML('Tom Tom'); - this.assertStableRerender(); - - assert.validateDeprecations( - /You set the 'name' property on a \{\{hash\}\} object. Setting properties on objects generated by \{\{hash\}\} is deprecated. Please update to use an object created with a tracked property or getter, or with a custom helper./u - ); - } - - @test - 'undefined hash keys can be updated'(assert: Assert) { - class FooBar extends GlimmerishComponent { - constructor(owner: object, args: { hash: Record }) { - super(owner, args); - args.hash['lastName'] = 'Chan'; - } - } - - this.registerComponent('Glimmer', 'FooBar', `{{yield @hash}}`, FooBar); - - this.render( - `{{values.firstName}} {{values.lastName}}` - ); - - this.assertHTML('Godfrey Chan'); - this.assertStableRerender(); - - assert.validateDeprecations( - /You set the 'lastName' property on a \{\{hash\}\} object. Setting properties on objects generated by \{\{hash\}\} is deprecated. Please update to use an object created with a tracked property or getter, or with a custom helper./u - ); - } } jitSuite(HashTest); diff --git a/packages/@glimmer/runtime/lib/helpers/hash.ts b/packages/@glimmer/runtime/lib/helpers/hash.ts index 3dcc77ddb1..0b19c7e87e 100644 --- a/packages/@glimmer/runtime/lib/helpers/hash.ts +++ b/packages/@glimmer/runtime/lib/helpers/hash.ts @@ -1,33 +1,10 @@ import type { CapturedArguments, Dict } from '@glimmer/interfaces'; import type { Reference } from '@glimmer/reference'; -import { deprecate } from '@glimmer/global-context'; import { createComputeRef } from '@glimmer/reference'; import { reifyNamed } from '../vm/arguments'; import { internalHelper } from './internal-helper'; -let wrapHashProxy: (hash: Record) => Record; - -if (import.meta.env.DEV) { - wrapHashProxy = (hash: Record) => { - return new Proxy(hash, { - set(target, key, value) { - deprecate( - `You set the '${String( - key - )}' property on a {{hash}} object. Setting properties on objects generated by {{hash}} is deprecated. Please update to use an object created with a tracked property or getter, or with a custom helper.`, - false, - { id: 'setting-on-hash' } - ); - - target[key as string] = value; - - return true; - }, - }); - }; -} - /** Use the `{{hash}}` helper to create a hash to pass as an option to your components. This is specially useful for contextual components where you can @@ -67,13 +44,7 @@ if (import.meta.env.DEV) { export const hash = internalHelper(({ named }: CapturedArguments): Reference> => { let ref = createComputeRef( () => { - let hash = reifyNamed(named); - - if (import.meta.env.DEV) { - hash = wrapHashProxy(hash); - } - - return hash; + return reifyNamed(named); }, null, 'hash'