From a3541cc98dd5d47e727e2f1ef2c44ab8f69e1b9a Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 3 May 2024 13:22:25 -0400 Subject: [PATCH 1/3] issue-1128 --- ember-resources/src/function-based/types.ts | 2 +- test-app/tests/core/issue-1128-test.gts | 44 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test-app/tests/core/issue-1128-test.gts diff --git a/ember-resources/src/function-based/types.ts b/ember-resources/src/function-based/types.ts index 5ee72b371..2333ac366 100644 --- a/ember-resources/src/function-based/types.ts +++ b/ember-resources/src/function-based/types.ts @@ -10,7 +10,7 @@ export interface InternalFunctionResourceConfig { [INTERNAL]: true; } -export const CURRENT = Symbol('ember-resources::CURRENT'); +export const CURRENT = Symbol('ember-resources::CURRENT') as unknown as 'CURRENT'; export interface GlintRenderable { /** diff --git a/test-app/tests/core/issue-1128-test.gts b/test-app/tests/core/issue-1128-test.gts new file mode 100644 index 000000000..dcd9d9f6b --- /dev/null +++ b/test-app/tests/core/issue-1128-test.gts @@ -0,0 +1,44 @@ +import Component from '@glimmer/component'; +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; + +import { cell, resource, resourceFactory, use } from 'ember-resources'; + +import type { Cell, Reactive} from 'ember-resources'; + + export type ClockNakedSignature = { + percentage: Cell; + counter: Cell; +}; + +export type ClockSignature = Reactive; + +interface Signature { + Args: {}; + Blocks: { + default: [ClockNakedSignature]; + }; + Element: HTMLDivElement; +} + +const Clock = resource(({ on }) => { + const counter = cell(0); + const percentage = cell(0); + + return { percentage, counter }; +}); + +export default class Refresher extends Component { + @use clock = Clock; + + +} + +module('issues/1128', function(hooks) { + setupRenderingTest(hooks); + + test('it works', async function () { + + }); + +}); From e7cd1e92ecff622bd2227763f7c57e4699753b2d Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 3 May 2024 13:26:19 -0400 Subject: [PATCH 2/3] test --- test-app/tests/core/issue-1128-test.gts | 29 ++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/test-app/tests/core/issue-1128-test.gts b/test-app/tests/core/issue-1128-test.gts index dcd9d9f6b..ac94591aa 100644 --- a/test-app/tests/core/issue-1128-test.gts +++ b/test-app/tests/core/issue-1128-test.gts @@ -1,10 +1,13 @@ import Component from '@glimmer/component'; +import { render } from '@ember/test-helpers'; import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; -import { cell, resource, resourceFactory, use } from 'ember-resources'; +import { cell, resource, use } from 'ember-resources'; -import type { Cell, Reactive} from 'ember-resources'; +import type { Reactive} from 'ember-resources'; + +type Cell = ReturnType>; export type ClockNakedSignature = { percentage: Cell; @@ -21,14 +24,23 @@ interface Signature { Element: HTMLDivElement; } -const Clock = resource(({ on }) => { +const Clock = resource(() => { const counter = cell(0); const percentage = cell(0); return { percentage, counter }; }); -export default class Refresher extends Component { + +class Refresher extends Component { + // use (the function) exposes a .current property, like a Cell + clock = use(this, Clock); + + +} + +class Refresher2 extends Component { + // with use (the decorator) the .current access is absorbed in an underlying getter @use clock = Clock; @@ -38,7 +50,14 @@ module('issues/1128', function(hooks) { setupRenderingTest(hooks); test('it works', async function () { - + await render(); }); }); From 98e4a85ed0a4a79d2ff3c15adaa07fa29950dbe6 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 3 May 2024 15:18:30 -0400 Subject: [PATCH 3/3] fix test --- test-app/tests/core/issue-1128-test.gts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/test-app/tests/core/issue-1128-test.gts b/test-app/tests/core/issue-1128-test.gts index ac94591aa..b56c592f8 100644 --- a/test-app/tests/core/issue-1128-test.gts +++ b/test-app/tests/core/issue-1128-test.gts @@ -32,32 +32,41 @@ const Clock = resource(() => { }); +// use (the function) exposes a .current property, like a Cell class Refresher extends Component { - // use (the function) exposes a .current property, like a Cell clock = use(this, Clock); } +// with use (the decorator) the .current access is absorbed in an underlying getter class Refresher2 extends Component { - // with use (the decorator) the .current access is absorbed in an underlying getter @use clock = Clock; } +const keys = (o: Record) => Object.keys(o).join(','); + module('issues/1128', function(hooks) { setupRenderingTest(hooks); - test('it works', async function () { + test('it works', async function (assert) { await render(); + + assert.dom('#one-keys').hasText('percentage,counter'); + assert.dom('#two-keys').hasText('percentage,counter'); + assert.dom('#one').hasText('0'); + assert.dom('#two').hasText('0'); }); });