Skip to content

Commit

Permalink
Merge pull request #13 from mausworks/feat/move-hook-to-index
Browse files Browse the repository at this point in the history
Move hook to index
  • Loading branch information
mausworks authored Jan 28, 2024
2 parents 96fef36 + be79b8c commit 1485003
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 20 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ npm i tyin
Create the hook:

```tsx
import storeHook from "tyin/hook";
import storeHook from "tyin";

export const useActivePage = storeHook(1);
```
Expand Down Expand Up @@ -60,7 +60,7 @@ const Pagination = ({ maxPage }: PaginationProps) => {
Real life applications are often complex, so let's add the `patch` function from the object plugin to handle partial updates:

```tsx
import storeHook from "tyin/hook";
import storeHook from "tyin";
import extend from "tyin/extend";
import objectAPI from "tyin/plugin-object";

Expand Down Expand Up @@ -91,7 +91,7 @@ In this example, we will add it, along with the persist plugin,
and a custom setter called `complete`:

```tsx
import storeHook from "tyin/hook";
import storeHook from "tyin";
import extend from "tyin/extend";
import arrayAPI from "tyin/plugin-array";
import persist from "tyin/plugin-persist";
Expand Down Expand Up @@ -141,7 +141,7 @@ After the store has been set up we can,
pull the state when a component mounts by using the `usePull` hook. To push or delete, we can just call the functions directly on the `sync` API.

```tsx
import storeHook from "tyin/hook";
import storeHook from "tyin";
import sync from "tyin/plugin-sync";
import extend from "tyin/extend";
import useHydrate from "tyin/plugin-sync/useHydrate";
Expand Down Expand Up @@ -202,18 +202,18 @@ fully featured state management solution in just a few bytes!

Tyin doesn't come with a single entry point—that's intentional!

It instead ships a couple of highly standalone modules,
It instead ships standalone modules that are meant to extend each other,
so that the user can import only the functionality that they need.

### 2. Genericism

Tyin exposes generic APIs that aim to maximize ergonomics and minimize bundle size.
Generic APIs facilitate code reuse, leading to synergies in consuming applications.
Generic APIs facilitate code reuse which leads to synergies in consuming applications.

For example: There is no `ObjectAPI.setKey(key, value)` function,
because `ObjectAPI.patch({ [key]: value })` covers that need
and a lot of other needs, simply by providing a generic API.
This API is powerful enough to receive aggressive reuse in the consuming app; leading to an even smaller bundle size overall.
and many others, simply by being more generic.
This API is powerful enough to receive aggressive reuse in the consuming app; leading to an even smaller overall bundle size.

### 3. Composability

Expand Down Expand Up @@ -244,7 +244,7 @@ store: 245 bytes, 212 gzipped
```

So, that means if you import everything; Tyin will add ~900 bytes to your bundle size,
and the most minimal implementation (just `tyin/hook`) would only add ~350 bytes.
and the most minimal implementation (importing just `tyin`) would only add ~350 bytes.

But this all depends on your bundler and configuration. In real-life scenarios it is often less. For dott.bio—using the `export-object.js` variant measured above—Tyin adds 550 bytes (according to `next/bundle-analyzer`).

Expand Down
2 changes: 1 addition & 1 deletion src/__test__/_export-all.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This is here to measure the bundle size of the library:
export * from "../hook";
export * from "../index";
export * from "../store";
export * from "../extend";
export * from "../plugin-array";
Expand Down
2 changes: 1 addition & 1 deletion src/__test__/_export-common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This is here to measure the bundle size of the library:
export * from "../hook";
export * from "../index";
export * from "../extend";
export * from "../plugin-object";
export * from "../plugin-persist";
2 changes: 1 addition & 1 deletion src/hook.ts → src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const bindHook = <T extends AnyState>(
* @template T The type of the state.
* @example
* ```ts
* import storeHook from "tyin/hook";
* import storeHook from "tyin";
* import extend from "tyin/extend";
* import objectAPI from "tyin/plugin-object";
*
Expand Down
2 changes: 1 addition & 1 deletion src/plugin-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type ArrayAPIPlugin<T extends any[] | null> = Plugin<
* @template T The type of the state, must be an array type.
* @example
* ```ts
* import storeHook from "tyin/hook";
* import storeHook from "tyin";
* import extend from "tyin/extend";
* import arrayAPI from "tyin/plugin-array";
*
Expand Down
2 changes: 1 addition & 1 deletion src/plugin-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const mergeLeft = <T extends ObjectLike | null, U = Partial<T>>(
* @template T The type of the state, must be an object type.
* @example
* ```ts
* import storeHook from "tyin/hook";
* import storeHook from "tyin";
* import extend from "tyin/extend";
* import objectAPI from "tyin/plugin-object";
*
Expand Down
2 changes: 1 addition & 1 deletion src/plugin-persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const localStorage = typeof window !== "undefined" ? window.localStorage : null;
* @template T The type of the state.
* @example
* ```ts
* import storeHook from "tyin/hook";
* import storeHook from "tyin";
* import extend from "tyin/extend";
* import persist from "tyin/plugin-persist";
*
Expand Down
2 changes: 1 addition & 1 deletion src/plugin-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type Reducer<T extends AnyState, A> = (state: T, action: A) => T;
* @template A The type of the actions.
* @example
* ```ts
* import storeHook from "tyin/hook";
* import storeHook from "tyin";
* import extend from "tyin/extend";
* import reducerAPI, { Action, Payload } from "tyin/plugin-reducer";
*
Expand Down
2 changes: 1 addition & 1 deletion src/plugin-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export type SyncPlugin<T extends AnyState, R extends {}> = Plugin<
*
* @example
* ```ts
* import storeHook from "tyin/hook";
* import storeHook from "tyin";
* import sync from "tyin/plugin-sync";
* import extend from "tyin/extend";
* import { Note } from "@/types";
Expand Down
2 changes: 1 addition & 1 deletion src/util-debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param callback A function to call.
* @example
* ```ts
* import storeHook from "tyin/hook";
* import storeHook from "tyin";
* import debounce from "tyin/util-debounce";
*
* const useExample = storeHook({ a: 1, b: 2 });
Expand Down
2 changes: 1 addition & 1 deletion src/util-deep-merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type DeepMerged<T extends PlainObject, P extends PlainObject> = {
* @param patch The patch object to merge from.
* @example
* ```
* import storeHook from "tyin/hook";
* import storeHook from "tyin";
* import extend from "tyin/extend";
* import objectAPI from "tyin/object";
* import deepMerge from "tyin/util-deep-merge";
Expand Down
2 changes: 1 addition & 1 deletion src/util-throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param callback A function to call.
* @example
* ```ts
* import storeHook from "tyin/hook";
* import storeHook from "tyin";
* import extend from "tyin/extend";
* import throttle from "tyin/util-throttle";
*
Expand Down

0 comments on commit 1485003

Please sign in to comment.