Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update function-based resource in-editor docs #947

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nine-hairs-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ember-resources": patch
---

Update in-editor docs on the function resource
11 changes: 11 additions & 0 deletions ember-resources/src/core/class-based/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ declare const __ResourceArgs__: unique symbol;
* which requires that the "State machine interpreter"
* is stopped when you are discarding the parent context (such as a component).
*
* _When would you reach for the class-based `Resource` instead of the function-based `resource`?_
*
* - the capabilities of the function-based resource and class-based resource are almost identical.
* the main difference is that function-based resources may represent a single a value
* (which could, itself, be a class instance, or object with properties),
* class-based-resources expose the whole class instance to the consumer.
*
* - function-based resources, however, are much easier to work with and understand, and have
* better intellisense capabilities.
*
*
* An example
* ```js
* import { Resource } from 'ember-resources';
Expand Down
15 changes: 3 additions & 12 deletions ember-resources/src/core/function-based/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { wrapForPlainUsage } from './utils';
import type { InternalFunctionResourceConfig, ResourceFn, ResourceFunction } from './types';

/**
* `resource` is an alternative API to the class-based `Resource`.
* It may provide a single read-only value and provides a way to optionally cleanup.
* `resource` provides a single reactive read-only value with lifetime and may have cleanup.
*
* Arguments passed to the `resource` function:
* ```js
Expand All @@ -31,15 +30,6 @@ import type { InternalFunctionResourceConfig, ResourceFn, ResourceFunction } fro
* );
* ```
*
* When would you reach for the class-based `Resource`?
* - the capabilities of the function-based resource and class-based resource are identical,
* with the exception that function-based resources may represent a single value, rather than
* an object with properties/methods (the only option with class-based resources)
*
* A function-resource
* - _must_ return a value.
* - cannot, itself, be async - but can interact with promises and update a value
*
* Example using `fetch` + `AbortController`
* ```js
* import { use, resource } from 'ember-resources';
Expand Down Expand Up @@ -80,7 +70,8 @@ import type { InternalFunctionResourceConfig, ResourceFn, ResourceFunction } fro
*
*
* Example using strict mode + `<template>` syntax and a template-only component:
* ```jsx gjs
*
* ```js
* import { resource } from 'ember-resources';
* import { TrackedObject } from 'tracked-built-ins';
*
Expand Down