Skip to content

Commit

Permalink
Update the service implementation to not require knowledge of a speci…
Browse files Browse the repository at this point in the history
…fic class-based resource implementation (#55)

* Update the service implementation to not require knowledge of a specific class-based resource implementation

* Add dep
  • Loading branch information
NullVoxPopuli authored Jan 13, 2024
1 parent 9e2355b commit d285981
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
52 changes: 52 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions reactiveweb/src/resource/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
macroCondition,
} from '@embroider/macros';

import { Resource } from 'ember-resources';

import type Owner from '@ember/owner';
import type { Stage1DecoratorDescriptor } from '#types';

Expand Down Expand Up @@ -167,17 +165,12 @@ export function service(resource: unknown) {
cache = invokeHelper(owner, resource);
caches.set(resource, cache);
associateDestroyableChild(owner, cache);
} else if ((resource as any).prototype instanceof Resource) {
assert(
`The .from() method on a type of Resource has been removed or altered. This is not allowed.`,
'from' in resource && resource.from === Resource.from
);

} else if ('from' in resource) {
/**
* We do a lot of lying internally to make TypeScript nice for consumers.
* But it does mean that we have to cast in our own code.
*/
let { definition } = (resource as typeof Resource).from(() => []) as unknown as any;
let { definition } = (resource as any).from(() => []) as unknown as any;

cache = invokeHelper(owner, definition);
caches.set(resource, cache);
Expand Down
1 change: 1 addition & 0 deletions tests/min-supported/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"@ember/test-waiters": "^3.1.0",
"@nullvoxpopuli/eslint-configs": "^3.2.2",
"ember-concurrency": "^3.1.1",
"ember-modify-based-class-resource": "^1.1.0",
"ember-resources": "^6.5.1",
"msw": "^1.3.2"
},
Expand Down
1 change: 1 addition & 0 deletions tests/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"@embroider/macros": "^1.13.4",
"@nullvoxpopuli/eslint-configs": "^3.2.2",
"ember-concurrency": "^3.1.1",
"ember-modify-based-class-resource": "^1.1.0",
"ember-resources": "^6.5.1",
"msw": "^1.3.2"
},
Expand Down
3 changes: 2 additions & 1 deletion tests/test-app/tests/resources/service-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { find,render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import { cell, Resource, resource } from 'ember-resources';
import { Resource } from 'ember-modify-based-class-resource';
import { cell, resource } from 'ember-resources';
import { service, serviceOverride } from 'reactiveweb/resource/service';
// This export is marked as @internal, so it is not present in
// the built d.ts files.
Expand Down

0 comments on commit d285981

Please sign in to comment.