diff --git a/docs/posts/endpoints.md b/docs/posts/endpoints.md index 38f5e60..8ce6fa6 100644 --- a/docs/posts/endpoints.md +++ b/docs/posts/endpoints.md @@ -329,7 +329,7 @@ function deserializeComment(com: any): Comment { const [schema, initialState] = createSchema({ cache: slice.table(), - loaders: slice.loader(), + loaders: slice.loaders(), token: slice.str(), articles: slice.table
(), people: slice.table(), diff --git a/docs/posts/getting-started.md b/docs/posts/getting-started.md index 3333dad..3b561d8 100644 --- a/docs/posts/getting-started.md +++ b/docs/posts/getting-started.md @@ -60,7 +60,7 @@ import { configureStore, createSchema, slice, storeMdw } from "starfx/store"; import { Provider, useCache } from "starfx/react"; const [schema, initialState] = createSchema({ - loaders: slice.loader(), + loaders: slice.loaders(), cache: slice.table(), }); diff --git a/docs/posts/schema.md b/docs/posts/schema.md index db624aa..8a908a2 100644 --- a/docs/posts/schema.md +++ b/docs/posts/schema.md @@ -25,13 +25,13 @@ associated logic: - [num](#num) - [str](#str) - [obj](#obj) -- [loader](#loader) +- [loaders](#loaders) - [table](#table) # Schema assumptions `createSchema` requires two slices by default in order for it and everything -inside `starfx` to function properly: `cache` and `loader`. +inside `starfx` to function properly: `cache` and `loaders`. Why do we require those slices? Because if we can assume those exist, we can build a lot of useful middleware and supervisors on top of that assumption. It's @@ -183,14 +183,14 @@ in your system. [Read more about entity factories.](https://bower.sh/entity-factories) -# `loader` +# `loaders` This is a specialized database table specific to managing loaders in `starfx`. [Read more about loaders here](/loader). ```ts const [schema] = createSchema({ - loaders: slice.loader(), + loaders: slice.loaders(), }); function*() { diff --git a/docs/posts/store.md b/docs/posts/store.md index 67579c1..d995742 100644 --- a/docs/posts/store.md +++ b/docs/posts/store.md @@ -49,7 +49,7 @@ interface User { // app-wide database for ui, api data, or anything that needs reactivity const [schema, initialState] = createSchema({ cache: slice.table(), - loaders: slice.loader(), + loaders: slice.loaders(), users: slice.table(), }); type WebState = typeof initialState; diff --git a/store/fx.ts b/store/fx.ts index 415a9a8..623a24a 100644 --- a/store/fx.ts +++ b/store/fx.ts @@ -2,7 +2,7 @@ import { Operation, Result } from "../deps.ts"; import type { ActionFnWithPayload, AnyState } from "../types.ts"; import type { FxStore, StoreUpdater, UpdaterCtx } from "./types.ts"; import { StoreContext } from "./context.ts"; -import { LoaderOutput } from "./slice/loader.ts"; +import { LoaderOutput } from "./slice/loaders.ts"; import { parallel, safe } from "../fx/mod.ts"; import { ThunkAction } from "../query/mod.ts"; import { getIdFromAction, take } from "../action.ts"; diff --git a/store/query.ts b/store/query.ts index f3a72c7..d6c3db5 100644 --- a/store/query.ts +++ b/store/query.ts @@ -3,7 +3,7 @@ import { compose } from "../compose.ts"; import type { AnyAction, AnyState, Next } from "../types.ts"; import { put } from "../action.ts"; import { select, updateStore } from "./fx.ts"; -import { LoaderOutput } from "./slice/loader.ts"; +import { LoaderOutput } from "./slice/loaders.ts"; import { TableOutput } from "./slice/table.ts"; export function store< diff --git a/store/slice/loader.ts b/store/slice/loaders.ts similarity index 97% rename from store/slice/loader.ts rename to store/slice/loaders.ts index 2a10d4d..5f754e2 100644 --- a/store/slice/loader.ts +++ b/store/slice/loaders.ts @@ -125,7 +125,7 @@ export interface LoaderOutput< const ts = () => new Date().getTime(); -export const createLoader = < +export const createLoaders = < M extends AnyState = AnyState, S extends AnyState = AnyState, >({ @@ -184,8 +184,8 @@ export const createLoader = < }; }; -export function loader< +export function loaders< M extends AnyState = AnyState, >(initialState?: Record>) { - return (name: string) => createLoader({ name, initialState }); + return (name: string) => createLoaders({ name, initialState }); } diff --git a/store/slice/mod.ts b/store/slice/mod.ts index 9f50e1c..5b59e24 100644 --- a/store/slice/mod.ts +++ b/store/slice/mod.ts @@ -6,16 +6,21 @@ import { obj, ObjOutput } from "./obj.ts"; import { defaultLoader, defaultLoaderItem, - loader, LoaderOutput, -} from "./loader.ts"; + loaders, +} from "./loaders.ts"; + export const slice = { str, num, table, any, obj, - loader, + loaders, + /** + * @deprecated Use `slice.loaders` instead + */ + loader: loaders, }; export { defaultLoader, defaultLoaderItem }; export type { diff --git a/store/types.ts b/store/types.ts index fbb7e82..fd168c1 100644 --- a/store/types.ts +++ b/store/types.ts @@ -1,4 +1,4 @@ -import type { LoaderOutput } from "./slice/loader.ts"; +import type { LoaderOutput } from "./slice/loaders.ts"; import type { TableOutput } from "./slice/table.ts"; import type { Callable, diff --git a/test/api.test.ts b/test/api.test.ts index 8f0c7c9..7f783c1 100644 --- a/test/api.test.ts +++ b/test/api.test.ts @@ -35,7 +35,7 @@ const mockUser: User = { id: "1", name: "test", email: "test@test.com" }; const testStore = () => { const [schema, initialState] = createSchema({ users: slice.table({ empty: emptyUser }), - loaders: slice.loader(), + loaders: slice.loaders(), cache: slice.table({ empty: {} }), }); const store = configureStore({ initialState }); diff --git a/test/batch.test.ts b/test/batch.test.ts index 8970e5e..e33a52c 100644 --- a/test/batch.test.ts +++ b/test/batch.test.ts @@ -12,7 +12,7 @@ const batch = describe("batch mdw"); it(batch, "should batch notify subscribers based on mdw", async () => { const [schema, initialState] = createSchema({ cache: slice.table({ empty: {} }), - loaders: slice.loader(), + loaders: slice.loaders(), }); const store = configureStore({ initialState, diff --git a/test/fetch.test.ts b/test/fetch.test.ts index 19a4014..b59a7d2 100644 --- a/test/fetch.test.ts +++ b/test/fetch.test.ts @@ -16,7 +16,7 @@ const mockUser = { id: "1", email: "test@starfx.com" }; const testStore = () => { const [schema, initialState] = createSchema({ - loaders: slice.loader(), + loaders: slice.loaders(), cache: slice.table({ empty: {} }), }); const store = configureStore({ initialState }); diff --git a/test/mdw.test.ts b/test/mdw.test.ts index 40e8e99..2380c14 100644 --- a/test/mdw.test.ts +++ b/test/mdw.test.ts @@ -37,7 +37,7 @@ const jsonBlob = (data: any) => { const testStore = () => { const [schema, initialState] = createSchema({ users: slice.table({ empty: emptyUser }), - loaders: slice.loader(), + loaders: slice.loaders(), cache: slice.table({ empty: {} }), }); const store = configureStore({ initialState }); diff --git a/test/persist.test.ts b/test/persist.test.ts index 9c5f44b..67a743b 100644 --- a/test/persist.test.ts +++ b/test/persist.test.ts @@ -15,7 +15,7 @@ const tests = describe("store"); it(tests, "can persist to storage adapters", async () => { const [schema, initialState] = createSchema({ token: slice.str(), - loaders: slice.loader(), + loaders: slice.loaders(), cache: slice.table({ empty: {} }), }); type State = typeof initialState; @@ -63,7 +63,7 @@ it(tests, "can persist to storage adapters", async () => { it(tests, "rehydrates state", async () => { const [schema, initialState] = createSchema({ token: slice.str(), - loaders: slice.loader(), + loaders: slice.loaders(), cache: slice.table({ empty: {} }), }); type State = typeof initialState; diff --git a/test/react.test.ts b/test/react.test.ts index eba1979..a3dcdf3 100644 --- a/test/react.test.ts +++ b/test/react.test.ts @@ -9,7 +9,7 @@ const tests = describe("react"); it(tests, () => { const [schema, initialState] = createSchema({ cache: slice.table(), - loaders: slice.loader(), + loaders: slice.loaders(), }); const store = createStore({ initialState }); React.createElement( diff --git a/test/schema.test.ts b/test/schema.test.ts index 4a1f342..bafc642 100644 --- a/test/schema.test.ts +++ b/test/schema.test.ts @@ -23,7 +23,7 @@ it(tests, "general types and functionality", async () => { dev: slice.any(false), currentUser: slice.obj(emptyUser), cache: slice.table({ empty: {} }), - loaders: slice.loader(), + loaders: slice.loaders(), }); const store = configureStore({ initialState }); @@ -73,7 +73,7 @@ it(tests, "can work with a nested object", async () => { const [db, initialState] = createSchema({ currentUser: slice.obj({ id: "", name: "", roles: [] }), cache: slice.table({ empty: {} }), - loaders: slice.loader(), + loaders: slice.loaders(), }); const store = configureStore({ initialState }); await store.run(function* () {