From e9d4a8a93d7cda2b9c3dc939c014977acaeb3a3e Mon Sep 17 00:00:00 2001 From: mausworks Date: Sun, 28 Jan 2024 23:05:10 +0100 Subject: [PATCH] feat: move "tyin/hook" to "tyin" BREAKING CHANGE --- README.md | 20 ++++++++++---------- src/__test__/_export-all.ts | 2 +- src/__test__/_export-common.ts | 2 +- src/{hook.ts => index.ts} | 2 +- src/plugin-array.ts | 2 +- src/plugin-object.ts | 2 +- src/plugin-persist.ts | 2 +- src/plugin-reducer.ts | 2 +- src/plugin-sync.ts | 2 +- src/util-debounce.ts | 2 +- src/util-deep-merge.ts | 2 +- src/util-throttle.ts | 2 +- 12 files changed, 21 insertions(+), 21 deletions(-) rename src/{hook.ts => index.ts} (98%) diff --git a/README.md b/README.md index 10c13c8..2b3b5d2 100644 --- a/README.md +++ b/README.md @@ -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); ``` @@ -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"; @@ -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"; @@ -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"; @@ -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, -so that the user can import only the functionality that they need. +It instead ships standalone modules that are specifically meant for +state management, and that can build on each other. ### 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 @@ -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`). diff --git a/src/__test__/_export-all.ts b/src/__test__/_export-all.ts index d02d9e2..cabcc5c 100644 --- a/src/__test__/_export-all.ts +++ b/src/__test__/_export-all.ts @@ -1,5 +1,5 @@ // This is here to measure the bundle size of the library: -export * from "../hook"; +export * from ".."; export * from "../store"; export * from "../extend"; export * from "../plugin-array"; diff --git a/src/__test__/_export-common.ts b/src/__test__/_export-common.ts index b629124..4d975ef 100644 --- a/src/__test__/_export-common.ts +++ b/src/__test__/_export-common.ts @@ -1,5 +1,5 @@ // This is here to measure the bundle size of the library: -export * from "../hook"; +export * from ".."; export * from "../extend"; export * from "../plugin-object"; export * from "../plugin-persist"; diff --git a/src/hook.ts b/src/index.ts similarity index 98% rename from src/hook.ts rename to src/index.ts index d918676..0e02181 100644 --- a/src/hook.ts +++ b/src/index.ts @@ -80,7 +80,7 @@ const bindHook = ( * @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"; * diff --git a/src/plugin-array.ts b/src/plugin-array.ts index 01ed0fb..5db614a 100644 --- a/src/plugin-array.ts +++ b/src/plugin-array.ts @@ -34,7 +34,7 @@ export type ArrayAPIPlugin = 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"; * diff --git a/src/plugin-object.ts b/src/plugin-object.ts index 2775fcc..54a9659 100644 --- a/src/plugin-object.ts +++ b/src/plugin-object.ts @@ -62,7 +62,7 @@ const mergeLeft = >( * @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"; * diff --git a/src/plugin-persist.ts b/src/plugin-persist.ts index 24ff5e2..0179e6e 100644 --- a/src/plugin-persist.ts +++ b/src/plugin-persist.ts @@ -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"; * diff --git a/src/plugin-reducer.ts b/src/plugin-reducer.ts index b0f3cb3..595ebfb 100644 --- a/src/plugin-reducer.ts +++ b/src/plugin-reducer.ts @@ -52,7 +52,7 @@ export type Reducer = (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"; * diff --git a/src/plugin-sync.ts b/src/plugin-sync.ts index 4cc046c..187e0ca 100644 --- a/src/plugin-sync.ts +++ b/src/plugin-sync.ts @@ -141,7 +141,7 @@ export type SyncPlugin = 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"; diff --git a/src/util-debounce.ts b/src/util-debounce.ts index 0514b0a..f1a7b6c 100644 --- a/src/util-debounce.ts +++ b/src/util-debounce.ts @@ -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 }); diff --git a/src/util-deep-merge.ts b/src/util-deep-merge.ts index e4e8aaf..21384b1 100644 --- a/src/util-deep-merge.ts +++ b/src/util-deep-merge.ts @@ -29,7 +29,7 @@ export type DeepMerged = { * @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"; diff --git a/src/util-throttle.ts b/src/util-throttle.ts index 7fcae1a..7d83611 100644 --- a/src/util-throttle.ts +++ b/src/util-throttle.ts @@ -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"; *