Skip to content

Commit 5233ef6

Browse files
Merge pull request #947 from NullVoxPopuli/update-docs
Update function-based resource in-editor docs
2 parents 817f802 + 16b844e commit 5233ef6

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

.changeset/nine-hairs-cry.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ember-resources": patch
3+
---
4+
5+
Update in-editor docs on the function resource

ember-resources/src/core/class-based/resource.ts

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ declare const __ResourceArgs__: unique symbol;
5151
* which requires that the "State machine interpreter"
5252
* is stopped when you are discarding the parent context (such as a component).
5353
*
54+
* _When would you reach for the class-based `Resource` instead of the function-based `resource`?_
55+
*
56+
* - the capabilities of the function-based resource and class-based resource are almost identical.
57+
* the main difference is that function-based resources may represent a single a value
58+
* (which could, itself, be a class instance, or object with properties),
59+
* class-based-resources expose the whole class instance to the consumer.
60+
*
61+
* - function-based resources, however, are much easier to work with and understand, and have
62+
* better intellisense capabilities.
63+
*
64+
*
5465
* An example
5566
* ```js
5667
* import { Resource } from 'ember-resources';

ember-resources/src/core/function-based/resource.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import { wrapForPlainUsage } from './utils';
99
import type { InternalFunctionResourceConfig, ResourceFn, ResourceFunction } from './types';
1010

1111
/**
12-
* `resource` is an alternative API to the class-based `Resource`.
13-
* It may provide a single read-only value and provides a way to optionally cleanup.
12+
* `resource` provides a single reactive read-only value with lifetime and may have cleanup.
1413
*
1514
* Arguments passed to the `resource` function:
1615
* ```js
@@ -31,15 +30,6 @@ import type { InternalFunctionResourceConfig, ResourceFn, ResourceFunction } fro
3130
* );
3231
* ```
3332
*
34-
* When would you reach for the class-based `Resource`?
35-
* - the capabilities of the function-based resource and class-based resource are identical,
36-
* with the exception that function-based resources may represent a single value, rather than
37-
* an object with properties/methods (the only option with class-based resources)
38-
*
39-
* A function-resource
40-
* - _must_ return a value.
41-
* - cannot, itself, be async - but can interact with promises and update a value
42-
*
4333
* Example using `fetch` + `AbortController`
4434
* ```js
4535
* import { use, resource } from 'ember-resources';
@@ -80,7 +70,8 @@ import type { InternalFunctionResourceConfig, ResourceFn, ResourceFunction } fro
8070
*
8171
*
8272
* Example using strict mode + `<template>` syntax and a template-only component:
83-
* ```jsx gjs
73+
*
74+
* ```js
8475
* import { resource } from 'ember-resources';
8576
* import { TrackedObject } from 'tracked-built-ins';
8677
*

0 commit comments

Comments
 (0)