repos / starfx

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

commit
ed75824
parent
072dd5b
author
Eric Bower
date
2024-02-23 16:52:06 +0000 UTC
chore: deprecate `slice.loader`

Use `slice.loaders` instead
16 files changed,  +30, -25
M docs/posts/endpoints.md
+1, -1
1@@ -329,7 +329,7 @@ function deserializeComment(com: any): Comment {
2 
3 const [schema, initialState] = createSchema({
4   cache: slice.table(),
5-  loaders: slice.loader(),
6+  loaders: slice.loaders(),
7   token: slice.str(),
8   articles: slice.table<Article>(),
9   people: slice.table<Person>(),
M docs/posts/getting-started.md
+1, -1
1@@ -60,7 +60,7 @@ import { configureStore, createSchema, slice, storeMdw } from "starfx/store";
2 import { Provider, useCache } from "starfx/react";
3 
4 const [schema, initialState] = createSchema({
5-  loaders: slice.loader(),
6+  loaders: slice.loaders(),
7   cache: slice.table(),
8 });
9 
M docs/posts/schema.md
+4, -4
 1@@ -25,13 +25,13 @@ associated logic:
 2 - [num](#num)
 3 - [str](#str)
 4 - [obj](#obj)
 5-- [loader](#loader)
 6+- [loaders](#loaders)
 7 - [table](#table)
 8 
 9 # Schema assumptions
10 
11 `createSchema` requires two slices by default in order for it and everything
12-inside `starfx` to function properly: `cache` and `loader`.
13+inside `starfx` to function properly: `cache` and `loaders`.
14 
15 Why do we require those slices? Because if we can assume those exist, we can
16 build a lot of useful middleware and supervisors on top of that assumption. It's
17@@ -183,14 +183,14 @@ in your system.
18 
19 [Read more about entity factories.](https://bower.sh/entity-factories)
20 
21-# `loader`
22+# `loaders`
23 
24 This is a specialized database table specific to managing loaders in `starfx`.
25 [Read more about loaders here](/loader).
26 
27 ```ts
28 const [schema] = createSchema({
29-  loaders: slice.loader(),
30+  loaders: slice.loaders(),
31 });
32 
33 function*() {
M docs/posts/store.md
+1, -1
1@@ -49,7 +49,7 @@ interface User {
2 // app-wide database for ui, api data, or anything that needs reactivity
3 const [schema, initialState] = createSchema({
4   cache: slice.table(),
5-  loaders: slice.loader(),
6+  loaders: slice.loaders(),
7   users: slice.table<User>(),
8 });
9 type WebState = typeof initialState;
M store/fx.ts
+1, -1
1@@ -2,7 +2,7 @@ import { Operation, Result } from "../deps.ts";
2 import type { ActionFnWithPayload, AnyState } from "../types.ts";
3 import type { FxStore, StoreUpdater, UpdaterCtx } from "./types.ts";
4 import { StoreContext } from "./context.ts";
5-import { LoaderOutput } from "./slice/loader.ts";
6+import { LoaderOutput } from "./slice/loaders.ts";
7 import { parallel, safe } from "../fx/mod.ts";
8 import { ThunkAction } from "../query/mod.ts";
9 import { getIdFromAction, take } from "../action.ts";
M store/query.ts
+1, -1
1@@ -3,7 +3,7 @@ import { compose } from "../compose.ts";
2 import type { AnyAction, AnyState, Next } from "../types.ts";
3 import { put } from "../action.ts";
4 import { select, updateStore } from "./fx.ts";
5-import { LoaderOutput } from "./slice/loader.ts";
6+import { LoaderOutput } from "./slice/loaders.ts";
7 import { TableOutput } from "./slice/table.ts";
8 
9 export function store<
R store/slice/loader.ts => store/slice/loaders.ts
+3, -3
 1@@ -125,7 +125,7 @@ export interface LoaderOutput<
 2 
 3 const ts = () => new Date().getTime();
 4 
 5-export const createLoader = <
 6+export const createLoaders = <
 7   M extends AnyState = AnyState,
 8   S extends AnyState = AnyState,
 9 >({
10@@ -184,8 +184,8 @@ export const createLoader = <
11   };
12 };
13 
14-export function loader<
15+export function loaders<
16   M extends AnyState = AnyState,
17 >(initialState?: Record<string, LoaderItemState<M>>) {
18-  return (name: string) => createLoader<M>({ name, initialState });
19+  return (name: string) => createLoaders<M>({ name, initialState });
20 }
M store/slice/mod.ts
+8, -3
 1@@ -6,16 +6,21 @@ import { obj, ObjOutput } from "./obj.ts";
 2 import {
 3   defaultLoader,
 4   defaultLoaderItem,
 5-  loader,
 6   LoaderOutput,
 7-} from "./loader.ts";
 8+  loaders,
 9+} from "./loaders.ts";
10+
11 export const slice = {
12   str,
13   num,
14   table,
15   any,
16   obj,
17-  loader,
18+  loaders,
19+  /**
20+   * @deprecated Use `slice.loaders` instead
21+   */
22+  loader: loaders,
23 };
24 export { defaultLoader, defaultLoaderItem };
25 export type {
M store/types.ts
+1, -1
1@@ -1,4 +1,4 @@
2-import type { LoaderOutput } from "./slice/loader.ts";
3+import type { LoaderOutput } from "./slice/loaders.ts";
4 import type { TableOutput } from "./slice/table.ts";
5 import type {
6   Callable,
M test/api.test.ts
+1, -1
1@@ -35,7 +35,7 @@ const mockUser: User = { id: "1", name: "test", email: "test@test.com" };
2 const testStore = () => {
3   const [schema, initialState] = createSchema({
4     users: slice.table<User>({ empty: emptyUser }),
5-    loaders: slice.loader(),
6+    loaders: slice.loaders(),
7     cache: slice.table({ empty: {} }),
8   });
9   const store = configureStore({ initialState });
M test/batch.test.ts
+1, -1
1@@ -12,7 +12,7 @@ const batch = describe("batch mdw");
2 it(batch, "should batch notify subscribers based on mdw", async () => {
3   const [schema, initialState] = createSchema({
4     cache: slice.table({ empty: {} }),
5-    loaders: slice.loader(),
6+    loaders: slice.loaders(),
7   });
8   const store = configureStore({
9     initialState,
M test/fetch.test.ts
+1, -1
1@@ -16,7 +16,7 @@ const mockUser = { id: "1", email: "test@starfx.com" };
2 
3 const testStore = () => {
4   const [schema, initialState] = createSchema({
5-    loaders: slice.loader(),
6+    loaders: slice.loaders(),
7     cache: slice.table({ empty: {} }),
8   });
9   const store = configureStore({ initialState });
M test/mdw.test.ts
+1, -1
1@@ -37,7 +37,7 @@ const jsonBlob = (data: any) => {
2 const testStore = () => {
3   const [schema, initialState] = createSchema({
4     users: slice.table<User>({ empty: emptyUser }),
5-    loaders: slice.loader(),
6+    loaders: slice.loaders(),
7     cache: slice.table({ empty: {} }),
8   });
9   const store = configureStore({ initialState });
M test/persist.test.ts
+2, -2
 1@@ -15,7 +15,7 @@ const tests = describe("store");
 2 it(tests, "can persist to storage adapters", async () => {
 3   const [schema, initialState] = createSchema({
 4     token: slice.str(),
 5-    loaders: slice.loader(),
 6+    loaders: slice.loaders(),
 7     cache: slice.table({ empty: {} }),
 8   });
 9   type State = typeof initialState;
10@@ -63,7 +63,7 @@ it(tests, "can persist to storage adapters", async () => {
11 it(tests, "rehydrates state", async () => {
12   const [schema, initialState] = createSchema({
13     token: slice.str(),
14-    loaders: slice.loader(),
15+    loaders: slice.loaders(),
16     cache: slice.table({ empty: {} }),
17   });
18   type State = typeof initialState;
M test/react.test.ts
+1, -1
1@@ -9,7 +9,7 @@ const tests = describe("react");
2 it(tests, () => {
3   const [schema, initialState] = createSchema({
4     cache: slice.table(),
5-    loaders: slice.loader(),
6+    loaders: slice.loaders(),
7   });
8   const store = createStore({ initialState });
9   React.createElement(
M test/schema.test.ts
+2, -2
 1@@ -23,7 +23,7 @@ it(tests, "general types and functionality", async () => {
 2     dev: slice.any<boolean>(false),
 3     currentUser: slice.obj<User>(emptyUser),
 4     cache: slice.table({ empty: {} }),
 5-    loaders: slice.loader(),
 6+    loaders: slice.loaders(),
 7   });
 8   const store = configureStore({ initialState });
 9 
10@@ -73,7 +73,7 @@ it(tests, "can work with a nested object", async () => {
11   const [db, initialState] = createSchema({
12     currentUser: slice.obj<UserWithRoles>({ id: "", name: "", roles: [] }),
13     cache: slice.table({ empty: {} }),
14-    loaders: slice.loader(),
15+    loaders: slice.loaders(),
16   });
17   const store = configureStore({ initialState });
18   await store.run(function* () {