Skip to content

Commit 1492440

Browse files
Merge pull request #1204 from gossi/named-args
Support named args for `resourceFactory()`
2 parents d1afaa8 + f3a6c29 commit 1492440

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

ember-resources/src/immediate-invocation-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ResourceInvokerManager {
3636
* change.
3737
*/
3838
const cache: State['cache'] = createCache(() => {
39-
let resource = fn(...args.positional) as object;
39+
let resource = fn(...[...args.positional, args.named]) as object;
4040

4141
setOwner(resource, this.owner);
4242

test-app/tests/core/function-resource/rendering-test.gts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { module, test } from 'qunit';
66
import { setupRenderingTest } from 'ember-qunit';
77
import { dependencySatisfies, importSync, macroCondition } from '@embroider/macros';
88

9-
import { cell,resource, use } from 'ember-resources';
9+
import { cell, resource, resourceFactory, use } from 'ember-resources';
1010

1111
import type Owner from '@ember/owner';
1212

@@ -42,7 +42,7 @@ module('Utils | (function) resource | rendering', function (hooks) {
4242

4343
let foo = new Test();
4444

45-
setOwner(foo, this.owner);
45+
setOwner(foo, this.owner);
4646

4747
// reminder that destruction is async
4848
let steps: string[] = [];
@@ -82,14 +82,32 @@ module('Utils | (function) resource | rendering', function (hooks) {
8282
assert.verifySteps(steps);
8383
});
8484

85+
test('with named args', async function (assert) {
86+
const resWithNamedArgs = resourceFactory((options) =>
87+
resource(() => {
88+
return options;
89+
})
90+
);
91+
92+
await render(<template>
93+
{{#let (resWithNamedArgs givenName="Luke" familyName="Skywalker") as |out|}}
94+
<output name="givenName">{{out.givenName}}</output>
95+
<output name="familyName">{{out.familyName}}</output>
96+
{{/let}}
97+
</template>);
98+
99+
assert.dom('output[name="givenName"]').hasText('Luke');
100+
assert.dom('output[name="familyName"]').hasText('Skywalker');
101+
});
102+
85103
test('with separate tracking frame', async function (assert) {
86104
class Test {
87105
@tracked num = 0;
88106
}
89107

90108
let foo = new Test();
91109

92-
setOwner(foo, this.owner);
110+
setOwner(foo, this.owner);
93111

94112
// reminder that destruction is async
95113
let steps: string[] = [];
@@ -140,7 +158,7 @@ module('Utils | (function) resource | rendering', function (hooks) {
140158
let inc = 0;
141159
let foo = new Test();
142160

143-
setOwner(foo, this.owner);
161+
setOwner(foo, this.owner);
144162

145163
let theResource = resource(({ on }) => {
146164
let i = inc;
@@ -188,7 +206,7 @@ module('Utils | (function) resource | rendering', function (hooks) {
188206

189207
let foo = new Test();
190208

191-
setOwner(foo, this.owner);
209+
setOwner(foo, this.owner);
192210

193211
let theResource = resource(({ on }) => {
194212
let i = foo.num;
@@ -236,7 +254,7 @@ module('Utils | (function) resource | rendering', function (hooks) {
236254

237255
let foo = new Test();
238256

239-
setOwner(foo, this.owner);
257+
setOwner(foo, this.owner);
240258

241259
let theResource = (_num: number) =>
242260
resource(({ on }) => {
@@ -304,7 +322,7 @@ module('Utils | (function) resource | rendering', function (hooks) {
304322

305323
let foo = new Test();
306324

307-
setOwner(foo, this.owner);
325+
setOwner(foo, this.owner);
308326

309327
await render(<template><out>{{foo.theResource}}</out></template>);
310328

@@ -349,7 +367,7 @@ module('Utils | (function) resource | rendering', function (hooks) {
349367

350368
let foo = new Test();
351369

352-
setOwner(foo, this.owner);
370+
setOwner(foo, this.owner);
353371

354372
await render(<template>
355373
{{#if foo.show}}
@@ -407,7 +425,7 @@ module('Utils | (function) resource | rendering', function (hooks) {
407425

408426
let foo = new Test();
409427

410-
setOwner(foo, this.owner);
428+
setOwner(foo, this.owner);
411429

412430
await render(<template>
413431
{{#if foo.show}}
@@ -458,7 +476,7 @@ module('Utils | (function) resource | rendering', function (hooks) {
458476

459477
let foo = new Test();
460478

461-
setOwner(foo, this.owner);
479+
setOwner(foo, this.owner);
462480

463481
await render(<template>
464482
{{#let (Wrapper foo.num) as |state|}}
@@ -517,7 +535,7 @@ module('Utils | (function) resource | rendering', function (hooks) {
517535

518536
let testData = new Test();
519537

520-
setOwner(testData, this.owner);
538+
setOwner(testData, this.owner);
521539

522540
setOwner(testData, this.owner);
523541

0 commit comments

Comments
 (0)