From 31ea1295f016a2b6cf943e2704ed8b9e2e135be6 Mon Sep 17 00:00:00 2001 From: react18-tools Date: Wed, 1 May 2024 02:33:51 +0000 Subject: [PATCH] upgrade deps && docs --- docs/.nojekyll | 1 + docs/1.getting-started.html | 101 ++++++++++++++++++ docs/functions/index.useRGS.html | 4 +- docs/functions/plugins_persist.persist.html | 4 +- docs/functions/utils.createHook.html | 4 +- docs/functions/utils.createSetter.html | 4 +- docs/functions/utils.createSubcriber.html | 4 +- docs/functions/utils.initWithPlugins.html | 4 +- docs/functions/utils.useRGSWithPlugins.html | 4 +- docs/functions/with_plugins.create.html | 4 +- docs/functions/with_plugins.withPlugins.html | 4 +- docs/index.html | 4 +- .../plugins_persist.PersistOptions.html | 6 +- docs/md-docs/1.getting-started.md | 84 --------------- docs/md-docs/2.leveraging-plugins.md | 64 ----------- docs/md-docs/3.creating-plugins.md | 1 - docs/modules/index.html | 4 +- docs/modules/plugins.html | 4 +- docs/modules/plugins_persist.html | 4 +- docs/modules/utils._internal_.html | 4 +- docs/modules/utils.html | 4 +- docs/modules/with_plugins.html | 4 +- docs/types/utils.Plugin.html | 2 +- docs/types/utils.SetStateAction.html | 2 +- docs/types/utils.SetterArgType.html | 2 +- docs/types/utils._internal_.Listener.html | 2 +- docs/types/utils._internal_.Mutate.html | 2 +- docs/types/utils._internal_.RGS.html | 2 +- docs/types/utils._internal_.Record.html | 4 +- docs/types/utils._internal_.Subscriber.html | 2 +- docs/variables/utils.globalRGS.html | 2 +- 31 files changed, 147 insertions(+), 194 deletions(-) create mode 100644 docs/.nojekyll create mode 100644 docs/1.getting-started.html delete mode 100644 docs/md-docs/1.getting-started.md delete mode 100644 docs/md-docs/2.leveraging-plugins.md delete mode 100644 docs/md-docs/3.creating-plugins.md diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 00000000..e2ac6616 --- /dev/null +++ b/docs/.nojekyll @@ -0,0 +1 @@ +TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. \ No newline at end of file diff --git a/docs/1.getting-started.html b/docs/1.getting-started.html new file mode 100644 index 00000000..fc4a985a --- /dev/null +++ b/docs/1.getting-started.html @@ -0,0 +1,101 @@ + + + + + + + +
Loading...
+ + + + + \ No newline at end of file diff --git a/docs/functions/index.useRGS.html b/docs/functions/index.useRGS.html index 2ab629a5..541e098c 100644 --- a/docs/functions/index.useRGS.html +++ b/docs/functions/index.useRGS.html @@ -1,4 +1,4 @@ -useRGS | Code Documentation
  • Use this hook similar to useState hook. +useRGS | Code Documentation

    • Use this hook similar to useState hook. The difference is that you need to pass a unique key - unique across the app to make this state accessible to all client components.

      @@ -9,4 +9,4 @@

    Example

    const [state, setState] = useRGS<number>("counter", 1);
     
    -
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/functions/plugins_persist.persist.html b/docs/functions/plugins_persist.persist.html index 7aa6bf4a..2353829f 100644 --- a/docs/functions/plugins_persist.persist.html +++ b/docs/functions/plugins_persist.persist.html @@ -1,3 +1,3 @@ -persist | Code Documentation
\ No newline at end of file diff --git a/docs/functions/utils.createHook.html b/docs/functions/utils.createHook.html index 7a39e3d0..d6f104b7 100644 --- a/docs/functions/utils.createHook.html +++ b/docs/functions/utils.createHook.html @@ -1,2 +1,2 @@ -createHook | Code Documentation
\ No newline at end of file +createHook | Code Documentation
\ No newline at end of file diff --git a/docs/functions/utils.createSetter.html b/docs/functions/utils.createSetter.html index c1ee3850..b07c1316 100644 --- a/docs/functions/utils.createSetter.html +++ b/docs/functions/utils.createSetter.html @@ -1,2 +1,2 @@ -createSetter | Code Documentation
\ No newline at end of file +createSetter | Code Documentation
\ No newline at end of file diff --git a/docs/functions/utils.createSubcriber.html b/docs/functions/utils.createSubcriber.html index 91f9146c..4b70afbb 100644 --- a/docs/functions/utils.createSubcriber.html +++ b/docs/functions/utils.createSubcriber.html @@ -1,2 +1,2 @@ -createSubcriber | Code Documentation
\ No newline at end of file +createSubcriber | Code Documentation
\ No newline at end of file diff --git a/docs/functions/utils.initWithPlugins.html b/docs/functions/utils.initWithPlugins.html index 7be16dd6..b8f472d3 100644 --- a/docs/functions/utils.initWithPlugins.html +++ b/docs/functions/utils.initWithPlugins.html @@ -1,2 +1,2 @@ -initWithPlugins | Code Documentation
  • Initialize the named store when invoked for the first time.

    -

    Type Parameters

    • T

    Parameters

    • key: string
    • Optional value: T
    • plugins: Plugin<T>[] = []
    • doNotInit: boolean = false

    Returns void

\ No newline at end of file +initWithPlugins | Code Documentation
  • Initialize the named store when invoked for the first time.

    +

    Type Parameters

    • T

    Parameters

    • key: string
    • Optional value: T
    • plugins: Plugin<T>[] = []
    • doNotInit: boolean = false

    Returns void

\ No newline at end of file diff --git a/docs/functions/utils.useRGSWithPlugins.html b/docs/functions/utils.useRGSWithPlugins.html index ed0036b2..3bffd0ce 100644 --- a/docs/functions/utils.useRGSWithPlugins.html +++ b/docs/functions/utils.useRGSWithPlugins.html @@ -1,4 +1,4 @@ -useRGSWithPlugins | Code Documentation
  • Use this hook similar to useState hook. +useRGSWithPlugins | Code Documentation

    • Use this hook similar to useState hook. The difference is that you need to pass a unique key - unique across the app to make this state accessible to all client components.

      @@ -11,4 +11,4 @@

    Example

    const [state, setState] = useRGS<number>("counter", 1);
     
    -
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/functions/with_plugins.create.html b/docs/functions/with_plugins.create.html index 1a898554..77b6fa01 100644 --- a/docs/functions/with_plugins.create.html +++ b/docs/functions/with_plugins.create.html @@ -1,4 +1,4 @@ -create | Code Documentation
  • Creates a store with plugins.

    +create | Code Documentation
    • Creates a store with plugins.

      Type Parameters

      • T

      Parameters

      • key: string

        Unique key to identify the store.

      • Optional value: T

        Initial value of the store.

      • Optional plugins: Plugin<T>[]

        Plugins to be applied to the store.

        @@ -7,4 +7,4 @@

      Example

      // in hook file, e.g., store.ts
      export const useMyRGS = create<type>(key, value, plugins);

      // in component file
      const [state, setState] = useMyRGS();
      -
    \ No newline at end of file +
\ No newline at end of file diff --git a/docs/functions/with_plugins.withPlugins.html b/docs/functions/with_plugins.withPlugins.html index 1979577b..f7ff5c11 100644 --- a/docs/functions/with_plugins.withPlugins.html +++ b/docs/functions/with_plugins.withPlugins.html @@ -1,4 +1,4 @@ -withPlugins | Code Documentation
  • Creates a hook similar to useRGS, but with plugins to be applied on first invocation.

    +withPlugins | Code Documentation
    • Creates a hook similar to useRGS, but with plugins to be applied on first invocation.

      Type Parameters

      • T

      Parameters

      • plugins: Plugin<T>[]

        Plugins to be applied to the store.

      Returns (<U>(key, value?, doNotInit?) => [U, SetStateAction<U>])

      A hook that automatically initializes the store (if not already initialized) with the given plugins.

      -
    \ No newline at end of file +
\ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 4716a012..26bef5be 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,4 +1,4 @@ -Code Documentation

Code Documentation

React18GlobalStore

test Maintainability codecov Version Downloads npm bundle size Gitpod ready-to-code

+Code Documentation

Code Documentation

React18GlobalStore

test Maintainability codecov Version Downloads npm bundle size Gitpod ready-to-code

Motivation

I've developed fantastic libraries leveraging React18 features using Zustand, and they performed admirably. However, when attempting to import from specific folders for better tree-shaking, the libraries encountered issues. Each import resulted in a separate Zustand store being created, leading to increased package size.

As a solution, I set out to create a lightweight, bare minimum store that facilitates shared state even when importing components from separate files, optimizing tree-shaking.

Features

✅ Full TypeScript Support

@@ -27,4 +27,4 @@

License

Licensed under the MPL 2.0 open source license.


-

with 💖 by Mayank Kumar Chaudhari

\ No newline at end of file +

with 💖 by Mayank Kumar Chaudhari

\ No newline at end of file diff --git a/docs/interfaces/plugins_persist.PersistOptions.html b/docs/interfaces/plugins_persist.PersistOptions.html index 2571e0f5..b61e4820 100644 --- a/docs/interfaces/plugins_persist.PersistOptions.html +++ b/docs/interfaces/plugins_persist.PersistOptions.html @@ -1,7 +1,7 @@ -PersistOptions | Code Documentation
interface PersistOptions {
    storage?: "local" | "session" | "cookie";
    sync?: boolean;
}

Properties

storage? +PersistOptions | Code Documentation
interface PersistOptions {
    storage?: "local" | "session" | "cookie";
    sync?: boolean;
}

Properties

Properties

storage?: "local" | "session" | "cookie"

Default Value

local
 
-
sync?: boolean

Default Value

true
+
sync?: boolean

Default Value

true
 
-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/md-docs/1.getting-started.md b/docs/md-docs/1.getting-started.md deleted file mode 100644 index e1d28c0d..00000000 --- a/docs/md-docs/1.getting-started.md +++ /dev/null @@ -1,84 +0,0 @@ -# Quick Start - -Welcome to the quick guide for using this library. - -## Installation - -To get started, you can install the package via your preferred package manager. Here are a few examples: - -```bash -$ pnpm add r18gs -``` - -or - -```bash -$ npm install r18gs -``` - -or - -```bash -$ yarn add r18gs -``` - -## Usage - -Utilize this hook similarly to the `useState` hook. However, ensure to pass a unique key, unique across the app, to identify and make this state accessible to all client components. - -```tsx -const [state, setState] = useRGS("counter", 1); -``` - -You can access the same state across all client-side components using a unique key. - -> It's advisable to store your keys in a separate file to prevent typos and unnecessary conflicts. - -### Example - -```tsx -// constants/global-states.ts -export const COUNTER = "counter"; -``` - -```tsx -// components/display.tsx -"use client"; - -import useRGS from "r18gs"; -import { COUNTER } from "../constants/global-states"; - -export default function Display() { - const [count] = useRGS(COUNTER); - return ( -
-

Client Component 2

- {count} -
- ); -} -``` - -```tsx -// components/counter.tsx -"use client"; - -import useRGS from "r18gs"; -import { COUNTER } from "../constants/global-states"; - -export default function Counter() { - const [count, setCount] = useRGS(COUNTER, 0); - return ( -
-

Client Component 1

- { - setCount(parseInt(e.target.value.trim())); - }} - type="number" - value={count} - /> -
- ); -} -``` diff --git a/docs/md-docs/2.leveraging-plugins.md b/docs/md-docs/2.leveraging-plugins.md deleted file mode 100644 index e8bd53c2..00000000 --- a/docs/md-docs/2.leveraging-plugins.md +++ /dev/null @@ -1,64 +0,0 @@ -# Leveraging Plugins - -Enhance your store's functionality by utilizing either the `create` function, `withPlugins` function, or the `useRGSWithPlugins` hook from `r18gs/dist/with-plugins`. This enables features such as storing to local storage, among others. - -## Creating a Store with the `create` Function - -```tsx -// store.ts -import { create } from "r18gs/dist/with-plugins"; -import { persist } from "r18gs/dist/plugins"; /** You can create your own plugin or import third-party plugins */ - -export const useMyPersistentCounterStore = create("persistent-counter", 0, [persist()]); -``` - -Now you can utilize `useMyPersistentCounterStore` similar to `useState` without specifying an initial value. - -```tsx -// inside your component -const [persistedCount, setPersistedCount] = useMyPersistentCounterStore(); -``` - -## Utilizing the `useRGSWithPlugins` Hook - -This function is beneficial if your requirements dictate that your `key` and/or initial value will depend on some props, etc. Or for some other reason you want to initialize the store from within a component (You need to use some variables available inside the component). - -```tsx -import { useRGSWithPlugins } from "r18gs/dist/with-plugin"; - -export function MyComponent(props: MyComponentProps) { - const [state, setState] = useRGSWithPlugins( - props.key, - props.initialVal, - props.plugins, - props.doNotInit, - ); - // ... -} -``` - -### `doNotInit` - -In some cases, you may not want to initialize the store immediately. In such cases, you can pass the fourth argument (`doNotInit`) as `true`. The default value is false. - -- When this argument is set to `true`, the store is created, but the setter function is set to null. Thus, you can access the initial value set by the first component that triggered this hook. However, it cannot be modified until the store is initialized, i.e., the hook is invoked by a component setting `doNotInit` to false (or skipping this argument). - -**Use case**: When you need that the store be used in many components, however, it should be initialized in a particular component only. - -## Creating a Custom Hook using the `withPlugins` Higher-Order Function - -This is a utility function that will be very helpful when you want to use the `useRGSWithPlugins` hook with the same plugins in multiple components. - -```ts -// custom hook file, e.g., store.ts -export const useMyRGS = withPlugins([plugin1, plugin2, ...]); -``` - -```tsx -export function MyComponent(props: MyComponentProps) { - const [state, setState] = useMyRGS(props.key, props.initialVal, props.doNotInit); - // ... -} -``` - -You can also create your own plugins. Refer to [Creating Plugins](./3.creating-plugins.md). diff --git a/docs/md-docs/3.creating-plugins.md b/docs/md-docs/3.creating-plugins.md deleted file mode 100644 index b7d3cbd8..00000000 --- a/docs/md-docs/3.creating-plugins.md +++ /dev/null @@ -1 +0,0 @@ -# Creating Plugins diff --git a/docs/modules/index.html b/docs/modules/index.html index 8af1a73e..c162033e 100644 --- a/docs/modules/index.html +++ b/docs/modules/index.html @@ -1,5 +1,5 @@ -index | Code Documentation

References

Plugin +index | Code Documentation

References

Re-exports Plugin
Re-exports SetStateAction
Re-exports SetterArgType
\ No newline at end of file +

References

Re-exports Plugin
Re-exports SetStateAction
Re-exports SetterArgType
\ No newline at end of file diff --git a/docs/modules/plugins.html b/docs/modules/plugins.html index 0cd16ade..eda518df 100644 --- a/docs/modules/plugins.html +++ b/docs/modules/plugins.html @@ -1,3 +1,3 @@ -plugins | Code Documentation

References

PersistOptions +plugins | Code Documentation

References

Re-exports PersistOptions
Re-exports persist
\ No newline at end of file +

References

Re-exports PersistOptions
Re-exports persist
\ No newline at end of file diff --git a/docs/modules/plugins_persist.html b/docs/modules/plugins_persist.html index 443044e2..2e96949e 100644 --- a/docs/modules/plugins_persist.html +++ b/docs/modules/plugins_persist.html @@ -1,3 +1,3 @@ -plugins/persist | Code Documentation

Module plugins/persist

Index

Interfaces

PersistOptions +plugins/persist | Code Documentation

Module plugins/persist

Index

Interfaces

Functions

\ No newline at end of file +
\ No newline at end of file diff --git a/docs/modules/utils._internal_.html b/docs/modules/utils._internal_.html index 8b19fcb8..9367d477 100644 --- a/docs/modules/utils._internal_.html +++ b/docs/modules/utils._internal_.html @@ -1,6 +1,6 @@ -<internal> | Code Documentation

Index

Type Aliases

Listener +<internal> | Code Documentation
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/modules/utils.html b/docs/modules/utils.html index 0ca5bfdd..aebe0492 100644 --- a/docs/modules/utils.html +++ b/docs/modules/utils.html @@ -1,4 +1,4 @@ -utils | Code Documentation

Index

Modules

<internal> +utils | Code Documentation
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/modules/with_plugins.html b/docs/modules/with_plugins.html index b8a26e2b..a7b82f84 100644 --- a/docs/modules/with_plugins.html +++ b/docs/modules/with_plugins.html @@ -1,4 +1,4 @@ -with-plugins | Code Documentation

References

useRGSWithPlugins +with-plugins | Code Documentation

References

Functions

References

Re-exports useRGSWithPlugins
\ No newline at end of file +

References

Re-exports useRGSWithPlugins
\ No newline at end of file diff --git a/docs/types/utils.Plugin.html b/docs/types/utils.Plugin.html index 5ea06513..2681c05f 100644 --- a/docs/types/utils.Plugin.html +++ b/docs/types/utils.Plugin.html @@ -1 +1 @@ -Plugin | Code Documentation

Type alias Plugin<T>

Plugin<T>: {
    init?: ((key, value, mutate) => void);
    onChange?: ((key, value?) => void);
}

Type Parameters

  • T

Type declaration

  • Optional init?: ((key, value, mutate) => void)
      • (key, value, mutate): void
      • Parameters

        • key: string
        • value: T | undefined
        • mutate: Mutate<T>

        Returns void

  • Optional onChange?: ((key, value?) => void)
      • (key, value?): void
      • Parameters

        • key: string
        • Optional value: T

        Returns void

\ No newline at end of file +Plugin | Code Documentation

Type alias Plugin<T>

Plugin<T>: {
    init?: ((key, value, mutate) => void);
    onChange?: ((key, value?) => void);
}

Type Parameters

  • T

Type declaration

  • Optional init?: ((key, value, mutate) => void)
      • (key, value, mutate): void
      • Parameters

        • key: string
        • value: T | undefined
        • mutate: Mutate<T>

        Returns void

  • Optional onChange?: ((key, value?) => void)
      • (key, value?): void
      • Parameters

        • key: string
        • Optional value: T

        Returns void

\ No newline at end of file diff --git a/docs/types/utils.SetStateAction.html b/docs/types/utils.SetStateAction.html index 2c9a9dd5..3d0d205e 100644 --- a/docs/types/utils.SetStateAction.html +++ b/docs/types/utils.SetStateAction.html @@ -1 +1 @@ -SetStateAction | Code Documentation

Type alias SetStateAction<T>

SetStateAction<T>: ((value) => void)

Type Parameters

  • T

Type declaration

\ No newline at end of file +SetStateAction | Code Documentation

Type alias SetStateAction<T>

SetStateAction<T>: ((value) => void)

Type Parameters

  • T

Type declaration

\ No newline at end of file diff --git a/docs/types/utils.SetterArgType.html b/docs/types/utils.SetterArgType.html index 91282ed2..9d638053 100644 --- a/docs/types/utils.SetterArgType.html +++ b/docs/types/utils.SetterArgType.html @@ -1 +1 @@ -SetterArgType | Code Documentation

Type alias SetterArgType<T>

SetterArgType<T>: T | ((prevState) => T)

Type Parameters

  • T

Type declaration

    • (prevState): T
    • Parameters

      • prevState: T

      Returns T

\ No newline at end of file +SetterArgType | Code Documentation

Type alias SetterArgType<T>

SetterArgType<T>: T | ((prevState) => T)

Type Parameters

  • T

Type declaration

    • (prevState): T
    • Parameters

      • prevState: T

      Returns T

\ No newline at end of file diff --git a/docs/types/utils._internal_.Listener.html b/docs/types/utils._internal_.Listener.html index 2e789c1e..6b2346ff 100644 --- a/docs/types/utils._internal_.Listener.html +++ b/docs/types/utils._internal_.Listener.html @@ -1 +1 @@ -Listener | Code Documentation
Listener: (() => void)

Type declaration

    • (): void
    • Returns void

\ No newline at end of file +Listener | Code Documentation
Listener: (() => void)

Type declaration

    • (): void
    • Returns void

\ No newline at end of file diff --git a/docs/types/utils._internal_.Mutate.html b/docs/types/utils._internal_.Mutate.html index b800b98d..54895884 100644 --- a/docs/types/utils._internal_.Mutate.html +++ b/docs/types/utils._internal_.Mutate.html @@ -1 +1 @@ -Mutate | Code Documentation
Mutate<T>: ((value?) => void)

Type Parameters

  • T

Type declaration

    • (value?): void
    • Parameters

      • Optional value: T

      Returns void

\ No newline at end of file +Mutate | Code Documentation
Mutate<T>: ((value?) => void)

Type Parameters

  • T

Type declaration

    • (value?): void
    • Parameters

      • Optional value: T

      Returns void

\ No newline at end of file diff --git a/docs/types/utils._internal_.RGS.html b/docs/types/utils._internal_.RGS.html index e4d75bb1..28e9abe4 100644 --- a/docs/types/utils._internal_.RGS.html +++ b/docs/types/utils._internal_.RGS.html @@ -1 +1 @@ -RGS | Code Documentation
RGS: [unknown, Listener[], SetStateAction<unknown> | null, Subscriber]
\ No newline at end of file +RGS | Code Documentation
RGS: [unknown, Listener[], SetStateAction<unknown> | null, Subscriber]
\ No newline at end of file diff --git a/docs/types/utils._internal_.Record.html b/docs/types/utils._internal_.Record.html index 0aec17b8..ef7c3b24 100644 --- a/docs/types/utils._internal_.Record.html +++ b/docs/types/utils._internal_.Record.html @@ -1,2 +1,2 @@ -Record | Code Documentation
Record<K, T>: {
    [P in K]: T
}

Construct a type with a set of properties K of type T

-

Type Parameters

  • K extends keyof any
  • T
\ No newline at end of file +Record | Code Documentation
Record<K, T>: {
    [P in K]: T
}

Construct a type with a set of properties K of type T

+

Type Parameters

  • K extends keyof any
  • T
\ No newline at end of file diff --git a/docs/types/utils._internal_.Subscriber.html b/docs/types/utils._internal_.Subscriber.html index 77306863..052e99cb 100644 --- a/docs/types/utils._internal_.Subscriber.html +++ b/docs/types/utils._internal_.Subscriber.html @@ -1 +1 @@ -Subscriber | Code Documentation
Subscriber: ((l) => (() => void))

Type declaration

    • (l): (() => void)
    • Parameters

      Returns (() => void)

        • (): void
        • Returns void

\ No newline at end of file +Subscriber | Code Documentation
Subscriber: ((l) => (() => void))

Type declaration

    • (l): (() => void)
    • Parameters

      Returns (() => void)

        • (): void
        • Returns void

\ No newline at end of file diff --git a/docs/variables/utils.globalRGS.html b/docs/variables/utils.globalRGS.html index de56e08d..1e270601 100644 --- a/docs/variables/utils.globalRGS.html +++ b/docs/variables/utils.globalRGS.html @@ -1 +1 @@ -globalRGS | Code Documentation

Variable globalRGSConst

globalRGS: Record<string, undefined | RGS> = globalThisForBetterMinification.rgs
\ No newline at end of file +globalRGS | Code Documentation

Variable globalRGSConst

globalRGS: Record<string, undefined | RGS> = globalThisForBetterMinification.rgs
\ No newline at end of file