Skip to content

Commit

Permalink
chore: deprecate slice.loader
Browse files Browse the repository at this point in the history
Use `slice.loaders` instead
  • Loading branch information
neurosnap committed Feb 23, 2024
1 parent 072dd5b commit ed75824
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/posts/endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Article>(),
people: slice.table<Person>(),
Expand Down
2 changes: 1 addition & 1 deletion docs/posts/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});

Expand Down
8 changes: 4 additions & 4 deletions docs/posts/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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*() {
Expand Down
2 changes: 1 addition & 1 deletion docs/posts/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<User>(),
});
type WebState = typeof initialState;
Expand Down
2 changes: 1 addition & 1 deletion store/fx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion store/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
6 changes: 3 additions & 3 deletions store/slice/loader.ts → store/slice/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
>({
Expand Down Expand Up @@ -184,8 +184,8 @@ export const createLoader = <
};
};

export function loader<
export function loaders<
M extends AnyState = AnyState,
>(initialState?: Record<string, LoaderItemState<M>>) {
return (name: string) => createLoader<M>({ name, initialState });
return (name: string) => createLoaders<M>({ name, initialState });
}
11 changes: 8 additions & 3 deletions store/slice/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion store/types.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const mockUser: User = { id: "1", name: "test", email: "[email protected]" };
const testStore = () => {
const [schema, initialState] = createSchema({
users: slice.table<User>({ empty: emptyUser }),
loaders: slice.loader(),
loaders: slice.loaders(),
cache: slice.table({ empty: {} }),
});
const store = configureStore({ initialState });
Expand Down
2 changes: 1 addition & 1 deletion test/batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const mockUser = { id: "1", email: "[email protected]" };

const testStore = () => {
const [schema, initialState] = createSchema({
loaders: slice.loader(),
loaders: slice.loaders(),
cache: slice.table({ empty: {} }),
});
const store = configureStore({ initialState });
Expand Down
2 changes: 1 addition & 1 deletion test/mdw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const jsonBlob = (data: any) => {
const testStore = () => {
const [schema, initialState] = createSchema({
users: slice.table<User>({ empty: emptyUser }),
loaders: slice.loader(),
loaders: slice.loaders(),
cache: slice.table({ empty: {} }),
});
const store = configureStore({ initialState });
Expand Down
4 changes: 2 additions & 2 deletions test/persist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ it(tests, "general types and functionality", async () => {
dev: slice.any<boolean>(false),
currentUser: slice.obj<User>(emptyUser),
cache: slice.table({ empty: {} }),
loaders: slice.loader(),
loaders: slice.loaders(),
});
const store = configureStore({ initialState });

Expand Down Expand Up @@ -73,7 +73,7 @@ it(tests, "can work with a nested object", async () => {
const [db, initialState] = createSchema({
currentUser: slice.obj<UserWithRoles>({ id: "", name: "", roles: [] }),
cache: slice.table({ empty: {} }),
loaders: slice.loader(),
loaders: slice.loaders(),
});
const store = configureStore({ initialState });
await store.run(function* () {
Expand Down

0 comments on commit ed75824

Please sign in to comment.