repos / starfx

supercharged async flow control library.
git clone https://github.com/neurosnap/starfx.git

commit
8c94373
parent
c80d74b
author
Eric Bower
date
2024-08-26 17:25:21 +0000 UTC
docs: copy
2 files changed,  +38, -0
M docs/posts/caching.md
+19, -0
 1@@ -30,7 +30,16 @@ When using an endpoint, this method simply stores whatever is put inside
 2 `ctx.json`. Then you can access that data via `useCache`.
 3 
 4 ```tsx
 5+import { createApi } from "starfx";
 6+import { useCache } from "starfx/react";
 7+
 8+const api = createApi();
 9 const fetchUsers = api.get("/users", api.cache());
10+
11+function App() {
12+  const { data = [] } = useCache(fetchUsers());
13+  return <div>{data.map((user) => <div>{user.name}</div>)}</div>;
14+}
15 ```
16 
17 `api.cache()` opts into automatic caching. This is really just an alias for:
18@@ -42,6 +51,16 @@ function*(ctx, next) {
19 }
20 ```
21 
22+The state slice for `cache` is simple, every thunk action has special properties
23+of one is a `key` field that is a hash of the entire user-defined action
24+payload:
25+
26+```js
27+{
28+  [action.payload.key]: {},
29+}
30+```
31+
32 # `timer` supervisor
33 
34 This supervisor can help us with how often we refetch data. This will help us
M docs/posts/thunks.md
+19, -0
 1@@ -118,6 +118,25 @@ A thunk action adheres to the
 2 > While not strictly necessary, it is highly recommended to keep actions JSON
 3 > serializable
 4 
 5+For thunks we have a more strict payload type signature with additional
 6+properties:
 7+
 8+```ts
 9+interface CreateActionPayload<P = any, ApiSuccess = any> {
10+  name: string; // the user-defined name
11+  options: P; // thunk payload described below
12+  key: string; // hash of entire thunk payload
13+}
14+
15+interface ThunkAction<P> {
16+  type: string;
17+  payload: CreateActionPayload<P>;
18+}
19+```
20+
21+This is the type signature for every action created automatically by
22+`createThunks` or `createApi`.
23+
24 # Thunk payload
25 
26 When calling a thunk, the user can provide a payload that is strictly enforced