- commit
- e7d0693
- parent
- 8984f7a
- author
- Eric Bower
- date
- 2024-08-17 02:00:05 +0000 UTC
docs: copy
2 files changed,
+34,
-1
+25,
-1
1@@ -47,7 +47,8 @@ const go = thunks.create("go", function* (ctx, next) {
2
3 const store = createStore({ initialState });
4 store.dispatch(go());
5-schema.loaders.selectById(store.getState(), { id: `${go}` }); // status = "error"; message = "boom!"
6+schema.loaders.selectById(store.getState(), { id: `${go}` });
7+// status = "error"; message = "boom!"
8 ```
9
10 # Shape
11@@ -76,3 +77,26 @@ export interface LoaderState<
12 isInitialLoading: boolean;
13 }
14 ```
15+
16+# `isLoading` vs `isInitialLoading`
17+
18+Why does this distinction exist? Well, when building a web app with `starfx`,
19+it's very common to have called the same endpoint multiple times. If that loader
20+has already successfully been called previously, `isInitialLoading` will **not**
21+flip states.
22+
23+The primary use case is: why show a loader if we can already show the user data?
24+
25+Conversely, `isLoading` will always be true when a loader is in "loading" state.
26+
27+This information is derived from `lastRun` and `lastSuccess`. Those are unix
28+timestamps of the last "loading" loader and the last time it was in "success"
29+state, respectively.
30+
31+# The `meta` property
32+
33+You can put whatever you want in there. This is a useful field when you want to
34+pass structured data from a thunk into the view on success or failure. Maybe
35+this is the new `id` for the entity you just created and the view needs to know
36+it. The `meta` prop is where you would be contextual information beyond a
37+`message` string.
+9,
-0
1@@ -28,6 +28,15 @@ Why do we require those slices? Because if we can assume those exist, we can
2 build a lot of useful middleware and supervisors on top of that assumption. It's
3 a place for `starfx` and third-party functionality to hold their state.
4
5+```ts
6+import { createSchema, slice } from "starfx";
7+
8+const [schema, initialState] = createSchema({
9+ cache: slice.table(),
10+ loaders: slice.loaders(),
11+});
12+```
13+
14 # Built-in slices
15
16 As a result, the following slices should cover the most common data types and