barrex 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,16 +25,16 @@ import { notifier } from "barrex";
25
25
 
26
26
  // Define your plain state object type
27
27
  interface CounterState {
28
- count: number;
29
- increment: () => boolean;
30
- reset: () => boolean;
28
+ count: number;
29
+ increment: () => boolean;
30
+ reset: () => boolean;
31
31
  }
32
32
 
33
33
  // Initialize the notifier
34
34
  export const counterNotifier = notifier<CounterState>({
35
- count: 0,
36
- increment: (): boolean => counterNotifier.count.set((c) => c + 1),
37
- reset: (): boolean => counterNotifier.count.set(0)
35
+ count: 0,
36
+ increment: (): boolean => counterNotifier.count.set((c) => c + 1),
37
+ reset: (): boolean => counterNotifier.count.set(0),
38
38
  });
39
39
  ```
40
40
 
@@ -46,16 +46,16 @@ import { useListener } from "barrex";
46
46
  import { counterNotifier } from "./counter-notifier";
47
47
 
48
48
  export function Counter() {
49
- // Fine-grained subscription: component only re-renders when `count` changes
50
- const count = useListener(counterNotifier.count);
51
-
52
- return (
53
- <div>
54
- <p>Count: {count}</p>
55
- <button onClick={counterNotifier.increment}>Increment</button>
56
- <button onClick={counterNotifier.reset}>Reset</button>
57
- </div>
58
- );
49
+ // Fine-grained subscription: component only re-renders when `count` changes
50
+ const count = useListener(counterNotifier.count);
51
+
52
+ return (
53
+ <div>
54
+ <p>Count: {count}</p>
55
+ <button onClick={counterNotifier.increment}>Increment</button>
56
+ <button onClick={counterNotifier.reset}>Reset</button>
57
+ </div>
58
+ );
59
59
  }
60
60
  ```
61
61
 
@@ -65,17 +65,17 @@ export function Counter() {
65
65
 
66
66
  - **[Core Concepts](./docs/core-concepts.md)**
67
67
  - **Utilities**
68
- - [notifier](./docs/utils/notifier.md)
69
- - [listener](./docs/utils/listener.md)
70
- - [multiListener](./docs/utils/multi-listener.md)
68
+ - [notifier](./docs/utils/notifier.md)
69
+ - [listener](./docs/utils/listener.md)
70
+ - [multiListener](./docs/utils/multi-listener.md)
71
71
  - **Hooks**
72
- - [useNotifier](./docs/hooks/use-notifier.md)
73
- - [useListener](./docs/hooks/use-listener.md)
74
- - [useMultiListener](./docs/hooks/use-multi-listener.md)
72
+ - [useNotifier](./docs/hooks/use-notifier.md)
73
+ - [useListener](./docs/hooks/use-listener.md)
74
+ - [useMultiListener](./docs/hooks/use-multi-listener.md)
75
75
  - **Components**
76
- - [Listener](./docs/components/listener.md)
77
- - [MultiListener](./docs/components/multi-listener.md)
78
- - [IsolatedContainer](./docs/components/isolated-container.md)
76
+ - [Listener](./docs/components/listener.md)
77
+ - [MultiListener](./docs/components/multi-listener.md)
78
+ - [IsolatedContainer](./docs/components/isolated-container.md)
79
79
 
80
80
  ---
81
81
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/helpers.ts","../src/notifier.ts","../src/utils/notifier.ts","../src/utils/listener.ts","../src/utils/multi-listener.ts","../src/hooks/useNotifier.ts","../src/hooks/useListener.ts","../src/hooks/useMultiListener.ts","../src/components/Listener.tsx","../src/components/MultiListener.tsx","../src/components/IsolatedContainer.tsx"],"names":["isObjectOrArray","value","isArray","isFunction","NotifierRoot","state","RootNode","Node","callback","listener","child","prevState","newState","key","index","prevChildState","_","prop","childNode","ChildNode","root","fromChild","parent","parentState","newParentState","functionCannotBeNotifierMessage","notifier","initialState","createNotifier","unsubscribe","multiListener","notifiers","unsubscribeFns","fn","useNotifier","useState","useListener","selector","areStatesEqual","useRef","useSyncExternalStore","nextState","areStatesEqualFn","prevValue","nextValue","useMultiListener","subscribe","useCallback","getSnapshot","ListenerComponent","stableChild","children","Listener","memo","prevProps","nextProps","MultiListenerComponent","MultiListener","IsolatedContainerComponent","jsx","Fragment","IsolatedContainer"],"mappings":"gFAAO,SAASA,CAAAA,CAAgBC,CAAAA,CAAiC,CAC7D,OAAO,OAAOA,GAAU,QAAA,EAAYA,CAAAA,GAAU,IAClD,CAEO,SAASC,CAAAA,CAAQD,EAAyC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AA,GACJA,CAAAA,CAAU,QAAA,CAAiB,IAAA,CAE3BD,CAAAA,CAAU,QAAA,GAAaC,EAAU,QAAA,EACjCD,CAAAA,CAAU,QAAA,GAAaC,CAAAA,CAAU,QAAA,EACjCD,CAAAA,CAAU,iBAAmBC,CAAAA,CAAU,cAAA,EACvCD,CAAAA,CAAU,WAAA,GAAgBC,CAAAA,CAAU,WAAA,EACpCD,EAAU,QAAA,GAAaC,CAAAA,CAAU,QAG7C,EC5CA,SAASC,CAAAA,CAAuB,CAC5B,SAAA,CAAAzB,CAAAA,CACA,SAAAM,CAAAA,CACA,cAAA,CAAAC,CAAAA,CACA,WAAA,CAAAY,CAAAA,CACA,QAAA,CAAAC,CACJ,CAAA,CAAQ,CACJ,IAAM9C,CAAAA,CAAQwC,CAAAA,CAAiBd,CAAAA,CAAWM,EAAUC,CAAc,CAAA,CAClE,OAAOa,CAAAA,CAAS9C,CAAAA,CAAO6C,CAAW,CACtC,CAuBO,IAAMO,CAAAA,CAA4CJ,UAAAA,CACrDG,CAAAA,CACA,CAACF,EAAWC,CAAAA,GACJA,CAAAA,CAAU,QAAA,CAAiB,IAAA,CAE3BD,CAAAA,CAAU,SAAA,GAAcC,EAAU,SAAA,EAClCD,CAAAA,CAAU,QAAA,GAAaC,CAAAA,CAAU,QAAA,EACjCD,CAAAA,CAAU,iBAAmBC,CAAAA,CAAU,cAAA,EACvCD,CAAAA,CAAU,WAAA,GAAgBC,CAAAA,CAAU,WAAA,EACpCD,EAAU,QAAA,GAAaC,CAAAA,CAAU,QAG7C,EC7CA,SAASG,CAAAA,CAA2B,CAAE,QAAA,CAAAP,CAAS,CAAA,CAA2B,CACtE,OAAOQ,cAAAA,CAAAC,mBAAAA,CAAA,CAAG,QAAA,CAAAT,CAAAA,CAAS,CACvB,CAwBO,IAAMU,CAAAA,CAAoBR,UAAAA,CAC7BK,CAAAA,CACA,IAAM,IACV","file":"index.cjs","sourcesContent":["export function isObjectOrArray(value: unknown): value is object {\r\n return typeof value === \"object\" && value !== null;\r\n}\r\n\r\nexport function isArray(value: unknown): value is Array<unknown> {\r\n return Array.isArray(value);\r\n}\r\n\r\nexport function isFunction(value: unknown): value is Function {\r\n return typeof value === \"function\";\r\n}","import type {\r\n NodeKey,\r\n SetState,\r\n StateUpdater,\r\n VoidCallback\r\n} from \"./types\";\r\nimport { isArray, isFunction, isObjectOrArray } from \"./utils/helpers\";\r\n\r\nexport class NotifierRoot {\r\n public state: unknown;\r\n public rootNode: RootNode;\r\n\r\n constructor(state: unknown) {\r\n this.state = state;\r\n this.rootNode = new RootNode(this);\r\n }\r\n}\r\n\r\nabstract class Node {\r\n protected cachedState: unknown;\r\n private listeners: Set<VoidCallback>;\r\n private children: Map<NodeKey, ChildNode>;\r\n public proxy: object;\r\n\r\n constructor() {\r\n this.cachedState = null;\r\n this.listeners = new Set();\r\n this.children = new Map();\r\n this.proxy = this.createProxy();\r\n }\r\n\r\n public abstract get(): unknown;\r\n public abstract set(state: SetState<unknown>, fromChild: boolean): boolean;\r\n\r\n public dispatchSet = (state: SetState<unknown>) => {\r\n return this.set(state, false);\r\n };\r\n\r\n private subscribe = (callback: VoidCallback) => {\r\n this.listeners.add(callback);\r\n return () => {\r\n this.listeners.delete(callback);\r\n };\r\n };\r\n\r\n protected notifyListeners() {\r\n this.listeners.forEach((listener) => listener());\r\n }\r\n\r\n private notifySubtree() {\r\n this.cachedState = null;\r\n this.notifyListeners();\r\n for (const child of this.children.values()) {\r\n child.notifySubtree();\r\n }\r\n }\r\n\r\n protected reconcileChildren(prevState: unknown, newState: unknown) {\r\n if (!isArray(prevState) || !isArray(newState)) {\r\n return;\r\n }\r\n for (const [key, child] of this.children) {\r\n const index = key as `${number}`;\r\n const prevChildState = prevState[index];\r\n const newChildState = newState[index];\r\n if (newChildState !== prevChildState) {\r\n child.notifySubtree();\r\n }\r\n }\r\n }\r\n\r\n private setTrap() { return false; }\r\n\r\n private createProxy() {\r\n return new Proxy(\r\n {},\r\n {\r\n get: (_, prop) => {\r\n if (prop === \"get\") return this.get;\r\n if (prop === \"set\") return this.dispatchSet;\r\n if (prop === \"subscribe\") return this.subscribe;\r\n\r\n const state = this.get();\r\n if (isObjectOrArray(state) && prop in state) {\r\n const value = (state as any)[prop];\r\n if (isFunction(value)) return value;\r\n\r\n let childNode = this.children.get(prop);\r\n if (!childNode) {\r\n childNode = new ChildNode(prop, this);\r\n this.children.set(prop, childNode);\r\n }\r\n return childNode.proxy;\r\n }\r\n },\r\n set: this.setTrap\r\n }\r\n );\r\n }\r\n}\r\n\r\nclass RootNode extends Node {\r\n private root: NotifierRoot;\r\n\r\n constructor(root: NotifierRoot) {\r\n super();\r\n this.root = root;\r\n }\r\n\r\n public get = () => this.root.state;\r\n\r\n public set(state: SetState<unknown>, fromChild: boolean) {\r\n const prevState = this.get();\r\n const newState = isFunction(state)\r\n ? (state as StateUpdater<unknown>)(prevState)\r\n : state;\r\n if (newState !== prevState) {\r\n this.root.state = newState;\r\n this.notifyListeners();\r\n if (!fromChild) {\r\n this.reconcileChildren(prevState, newState);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n}\r\n\r\nclass ChildNode extends Node {\r\n private key: NodeKey;\r\n private parent: Node;\r\n\r\n constructor(key: NodeKey, parent: Node) {\r\n super();\r\n this.key = key;\r\n this.parent = parent;\r\n }\r\n\r\n public get = (): unknown => {\r\n if (this.cachedState !== null) {\r\n return this.cachedState;\r\n }\r\n const state = (this.parent.get() as any)[this.key];\r\n this.cachedState = state;\r\n return state;\r\n }\r\n\r\n public set(state: SetState<unknown>, fromChild: boolean) {\r\n const parentState = this.parent.get();\r\n const prevState = (parentState as any)[this.key];\r\n const newState = isFunction(state)\r\n ? (state as StateUpdater<unknown>)(prevState)\r\n : state;\r\n if (newState !== prevState) {\r\n const newParentState = Object.assign(\r\n isArray(parentState) ? [] : {},\r\n parentState\r\n );\r\n (newParentState as any)[this.key] = newState;\r\n const isSet = this.parent.set(newParentState, true);\r\n if (isSet) {\r\n this.cachedState = newState;\r\n this.notifyListeners();\r\n if (!fromChild) {\r\n this.reconcileChildren(prevState, newState);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n return false;\r\n }\r\n}","import { isFunction } from \"./helpers\";\r\nimport { NotifierRoot } from \"../notifier\";\r\nimport type { InitialState, Notifier } from \"../types\";\r\n\r\nconst functionCannotBeNotifierMessage =\r\n \"A function cannot be a notifier. Replace it with other value, or add it as a property/method inside an object, or don't wrap it with notifier.\";\r\n\r\n/**\r\n * Creates a core, global root-level state container wrapped in a deeply reactive proxy tree.\r\n * \r\n * @remarks\r\n * Serves as the primary entry point for global stores outside of React. Every nested property \r\n * automatically becomes a sub-notifier. Raw functions cannot be notifiers and will throw an error.\r\n * \r\n * @see [Barrex Docs](./docs/utils/notifier.md)\r\n * \r\n * @template T The shape of the initial state.\r\n * @param initialState The initial value of the state, or a lazy initialization function returning the state.\r\n * @returns A root Notifier proxy instance.\r\n * \r\n * @example\r\n * ```ts\r\n * import { notifier } from \"barrex\";\r\n * \r\n * const authNotifier = notifier({\r\n * user: null,\r\n * isAuthenticated: false\r\n * });\r\n * ```\r\n */\r\nexport function notifier<T>(initialState: InitialState<T>): Notifier<T> {\r\n const state = (isFunction(initialState)\r\n ? (initialState as () => T)()\r\n : initialState) as T;\r\n if (isFunction(state)) {\r\n throw new Error(functionCannotBeNotifierMessage);\r\n }\r\n return createNotifier(state);\r\n}\r\n\r\nfunction createNotifier<T>(state: T): Notifier<T> {\r\n const root = new NotifierRoot(state);\r\n return root.rootNode.proxy as Notifier<T>;\r\n}","import type { ListenerCallback, Notifier, VoidCallback } from \"../types\";\r\n\r\n/**\r\n * Subscribes imperatively to a `barrex` notifier outside of React component trees.\r\n * \r\n * @remarks\r\n * Executes the callback immediately upon registration with the current state value, \r\n * and subsequently every time the notifier updates. Returns a cleanup function to unsubscribe.\r\n * \r\n * @see [Barrex Docs](./docs/utils/listener.md)\r\n * \r\n * @param notifier The source notifier instance to subscribe to.\r\n * @param callback A callback function invoked immediately and on every state update.\r\n * @returns A cleanup function to remove the subscription.\r\n * \r\n * @example\r\n * ```ts\r\n * import { listener } from \"barrex\";\r\n * \r\n * const unsubscribe = listener(themeNotifier, (theme) => {\r\n * localStorage.setItem(\"theme\", theme);\r\n * });\r\n * ```\r\n */\r\nexport function listener<T>(\r\n notifier: Notifier<T>,\r\n callback: ListenerCallback<T>\r\n): VoidCallback {\r\n const unsubscribe = notifier.subscribe(() => {\r\n callback(notifier.get());\r\n });\r\n callback(notifier.get());\r\n return unsubscribe;\r\n}","import type {\r\n InferNotifierValues,\r\n ListenerCallback,\r\n Notifier,\r\n VoidCallback\r\n} from \"../types\";\r\n\r\n/**\r\n * Subscribes imperatively to multiple `barrex` notifiers simultaneously outside of React.\r\n * \r\n * @remarks\r\n * Accepts a tuple array of notifiers, infers their types automatically, executes \r\n * the callback immediately with the initial values tuple, and returns a single composite cleanup function.\r\n * \r\n * @see [Barrex Docs](./docs/utils/multi-listener.md)\r\n * \r\n * @param notifiers A readonly tuple array of source notifiers to subscribe to.\r\n * @param callback A callback function invoked immediately with the values tuple and on subsequent updates.\r\n * @returns A composite cleanup function to unsubscribe from all provided notifiers.\r\n * \r\n * @example\r\n * ```ts\r\n * import { multiListener } from \"barrex\";\r\n * \r\n * const unsubscribe = multiListener(\r\n * [userNotifier.name, settingsNotifier.theme],\r\n * ([name, theme]) => {\r\n * console.log(`User: ${name}, Theme: ${theme}`);\r\n * }\r\n * );\r\n * ```\r\n */\r\nexport function multiListener<\r\n const T extends readonly Notifier<unknown>[]\r\n>(\r\n notifiers: T,\r\n callback: ListenerCallback<InferNotifierValues<T>>\r\n): VoidCallback {\r\n const listener = () => {\r\n const state = notifiers.map((notifier) => notifier.get()) as any;\r\n callback(state);\r\n };\r\n const unsubscribeFns = notifiers.map((notifier) => {\r\n return notifier.subscribe(listener);\r\n });\r\n const unsubscribe = () => unsubscribeFns.forEach((fn) => fn());\r\n listener();\r\n return unsubscribe;\r\n}","import { useState } from \"react\";\r\n\r\nimport type { InitialState, Notifier } from \"../types\";\r\nimport { notifier as createNotifier } from \"../utils/notifier\";\r\n\r\n/**\r\n * Creates a component-scoped, lazy-initialized notifier with automatic \r\n * proxy-driven nested reactivity.\r\n * \r\n * @remarks\r\n * Tied directly to the component lifecycle. Every property on the initial state \r\n * object automatically becomes a first-class sub-notifier.\r\n * \r\n * @see [Barrex Docs](./docs/hooks/use-notifier.md)\r\n * \r\n * @template T The shape of the initial state.\r\n * @param initialState The initial value or a lazy initializer function returning the state.\r\n * @returns A root Notifier proxy instance.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useNotifier, useListener } from \"barrex\";\r\n * \r\n * function Profile() {\r\n * const userNotifier = useNotifier({ name: \"Alice\", age: 40 });\r\n * const name = useListener(userNotifier.name);\r\n * return <p>{name}</p>;\r\n * }\r\n * ```\r\n */\r\nexport function useNotifier<T>(initialState: InitialState<T>): Notifier<T> {\r\n const [notifier] = useState(() => createNotifier(initialState));\r\n return notifier;\r\n}","import { useRef, useSyncExternalStore } from \"react\";\r\n\r\nimport type { Notifier, StatesComparer, StateSelector } from \"../types\";\r\n\r\n/**\r\n * Subscribes a React component to a `barrex` notifier, enabling precise, \r\n * fine-grained reactivity using `useSyncExternalStore`.\r\n * \r\n * @remarks\r\n * Components re-render only when the exact state slice or computed selector \r\n * value updates, preventing unnecessary re-renders across the tree.\r\n * \r\n * @see [Barrex Docs](./docs/hooks/use-listener.md)\r\n * \r\n * @template T The raw type of the source notifier state.\r\n * @template U The resolved type after applying the selector.\r\n * \r\n * @param notifier The source notifier instance to subscribe to.\r\n * @param selector Optional function to transform or compute a specific slice from the notifier state.\r\n * @param areStatesEqual Optional custom comparer. Returns true to reuse the previous state reference and skip re-renders.\r\n * @returns The current resolved state (raw or selected).\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useListener } from \"barrex\";\r\n * \r\n * function Counter() {\r\n * const count = useListener(counterNotifier);\r\n * return <span>Count: {count}</span>;\r\n * }\r\n * ```\r\n */\r\nexport function useListener<T, U = T>(\r\n notifier: Notifier<T>,\r\n selector?: StateSelector<T, U>,\r\n areStatesEqual?: StatesComparer<U>\r\n): U {\r\n const prevState = useRef<U>(null);\r\n\r\n return useSyncExternalStore(\r\n notifier.subscribe,\r\n () => {\r\n const nextState = selector\r\n ? selector(notifier.get())\r\n : notifier.get() as unknown as U;\r\n if (areStatesEqual && prevState.current !== null) {\r\n const areEqual = areStatesEqual(prevState.current, nextState);\r\n if (areEqual) return prevState.current;\r\n }\r\n prevState.current = nextState;\r\n return nextState;\r\n },\r\n () => (selector ? selector(notifier.get()) : notifier.get() as unknown as U)\r\n );\r\n}","import { useCallback, useRef, useSyncExternalStore } from \"react\";\r\n\r\nimport type {\r\n InferNotifierValues,\r\n Notifier,\r\n StatesComparer,\r\n StateSelector,\r\n VoidCallback\r\n} from \"../types\";\r\nimport { isArray } from \"../utils/helpers\";\r\n\r\nfunction areStatesEqualFn<T>(prevState: T, nextState: T) {\r\n if (\r\n isArray(prevState) &&\r\n isArray(nextState) &&\r\n prevState.length === nextState.length\r\n ) {\r\n return prevState.every((prevValue, index) => {\r\n const nextValue = nextState[index];\r\n return prevValue === nextValue;\r\n });\r\n }\r\n return prevState === nextState;\r\n};\r\n\r\n/**\r\n * Subscribes a React component to multiple notifiers simultaneously, \r\n * offering complete type safety and optimized derivations.\r\n * \r\n * @remarks\r\n * Bundles multiple notifier subscriptions into a single unified cleanup routine \r\n * and includes smart array/tuple shallow comparison by default.\r\n * \r\n * @see [Barrex Docs](./docs/hooks/use-multi-listener.md)\r\n * \r\n * @param notifiers A readonly tuple array of source notifiers to subscribe to.\r\n * @param selector Optional function to transform or combine the tuple values into a custom shape.\r\n * @param areStatesEqual Optional custom comparator. Defaults to a smart tuple-aware shallow equality checker.\r\n * @returns The resolved state tuple or the computed selector output.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useMultiListener } from \"barrex\";\r\n * \r\n * function Header() {\r\n * const [name, theme] = useMultiListener([userNotifier.name, themeNotifier]);\r\n * return <header className={theme}>Welcome, {name}</header>;\r\n * }\r\n * ```\r\n */\r\nexport function useMultiListener<\r\n const T extends readonly Notifier<unknown>[],\r\n const U\r\n>(\r\n notifiers: T,\r\n selector: StateSelector<InferNotifierValues<T>, U>,\r\n areStatesEqual?: StatesComparer<U>\r\n): U;\r\n\r\nexport function useMultiListener<\r\n const T extends readonly Notifier<unknown>[]\r\n>(\r\n notifiers: T,\r\n selector?: undefined,\r\n areStatesEqual?: StatesComparer<InferNotifierValues<T>>\r\n): InferNotifierValues<T>;\r\n\r\nexport function useMultiListener(\r\n notifiers: Notifier<unknown>[],\r\n selector?: StateSelector<any, any>,\r\n areStatesEqual: StatesComparer<any> = areStatesEqualFn\r\n): unknown {\r\n const prevState = useRef<unknown>(null);\r\n\r\n const subscribe = useCallback((callback: VoidCallback) => {\r\n const unsubscribeFns = notifiers.map((notifier) => {\r\n return notifier.subscribe(callback);\r\n });\r\n return () => unsubscribeFns.forEach((fn) => fn());\r\n }, notifiers);\r\n\r\n const getSnapshot = () => {\r\n const state = notifiers.map((notifier) => notifier.get());\r\n const nextState = selector ? selector(state) : state;\r\n if (prevState.current !== null) {\r\n const areEqual = areStatesEqual(prevState.current, nextState);\r\n if (areEqual) return prevState.current;\r\n }\r\n prevState.current = nextState;\r\n return nextState;\r\n };\r\n\r\n return useSyncExternalStore(\r\n subscribe,\r\n getSnapshot,\r\n getSnapshot\r\n );\r\n}","import { memo } from \"react\";\r\n\r\nimport type { ListenerProps } from \"../types\";\r\nimport { useListener } from \"../hooks/useListener\";\r\n\r\nfunction ListenerComponent<T, U = T>({\r\n notifier,\r\n selector,\r\n areStatesEqual,\r\n stableChild,\r\n children\r\n}: ListenerProps<T, U>) {\r\n const state = useListener(notifier, selector, areStatesEqual);\r\n return children(state, stableChild);\r\n}\r\n\r\n/**\r\n * A declarative component wrapper that brings fine-grained reactivity \r\n * and granular performance optimization directly into your JSX tree.\r\n * \r\n * @remarks\r\n * Confines updates strictly to its render-prop children without forcing \r\n * an entire component function to re-render.\r\n * \r\n * @see [Barrex Docs](./docs/components/listener.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { Listener } from \"barrex\";\r\n * \r\n * <Listener notifier={userNotifier.name}>\r\n * {(name) => <h1>Welcome, {name}!</h1>}\r\n * </Listener>\r\n * ```\r\n */\r\nexport const Listener = memo(\r\n ListenerComponent,\r\n (prevProps, nextProps) => {\r\n if (nextProps.isolated) return true;\r\n return (\r\n prevProps.notifier === nextProps.notifier &&\r\n prevProps.selector === nextProps.selector &&\r\n prevProps.areStatesEqual === nextProps.areStatesEqual &&\r\n prevProps.stableChild === nextProps.stableChild &&\r\n prevProps.children === nextProps.children\r\n );\r\n }\r\n) as typeof ListenerComponent;","import { memo } from \"react\";\r\n\r\nimport { useMultiListener } from \"../hooks/useMultiListener\";\r\nimport type { MultiListenerComponent as MultiListenerComponentType } from \"../types\";\r\n\r\nfunction MultiListenerComponent({\r\n notifiers,\r\n selector,\r\n areStatesEqual,\r\n stableChild,\r\n children\r\n}: any) {\r\n const state = useMultiListener(notifiers, selector, areStatesEqual);\r\n return children(state, stableChild);\r\n}\r\n\r\n/**\r\n * An advanced declarative component wrapper that enables fine-grained \r\n * subscriptions to multiple notifiers simultaneously with full type safety.\r\n * \r\n * @remarks\r\n * Automatically infers tuple types from the provided notifiers array \r\n * and includes smart array equality checking.\r\n * \r\n * @see [Barrex Docs](./docs/components/multi-listener.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { MultiListener } from \"barrex\";\r\n * \r\n * <MultiListener notifiers={[userNotifier.name, cartNotifier.count]}>\r\n * {([name, count]) => <p>{name} has {count} items</p>}\r\n * </MultiListener>\r\n * ```\r\n */\r\nexport const MultiListener: MultiListenerComponentType = memo(\r\n MultiListenerComponent,\r\n (prevProps, nextProps) => {\r\n if (nextProps.isolated) return true;\r\n return (\r\n prevProps.notifiers === nextProps.notifiers &&\r\n prevProps.selector === nextProps.selector &&\r\n prevProps.areStatesEqual === nextProps.areStatesEqual &&\r\n prevProps.stableChild === nextProps.stableChild &&\r\n prevProps.children === nextProps.children\r\n );\r\n }\r\n);","import { memo } from \"react\";\r\n\r\nimport type { IsolatedContainerProps } from \"../types\";\r\n\r\nfunction IsolatedContainerComponent({ children }: IsolatedContainerProps) {\r\n return <>{children}</>;\r\n}\r\n\r\n/**\r\n * A boundary component designed to completely shield its child \r\n * subtree from parent-driven re-render cascades.\r\n * \r\n * @remarks\r\n * Children inside an `IsolatedContainer` can still re-render independently \r\n * based on their own local state or external reactive bindings (like `barrex` notifiers).\r\n * \r\n * @see [Barrex Docs](./docs/components/isolated-container.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { IsolatedContainer } from \"barrex\";\r\n * \r\n * <IsolatedContainer>\r\n * <StaticHeader/>\r\n * <CounterWidget/>\r\n * </IsolatedContainer>\r\n * ```\r\n */\r\nexport const IsolatedContainer = memo(\r\n IsolatedContainerComponent,\r\n () => true\r\n) as typeof IsolatedContainerComponent;"]}
1
+ {"version":3,"sources":["../src/utils/helpers.ts","../src/notifier.ts","../src/utils/notifier.ts","../src/utils/listener.ts","../src/utils/multi-listener.ts","../src/hooks/useNotifier.ts","../src/hooks/useListener.ts","../src/hooks/useMultiListener.ts","../src/components/Listener.tsx","../src/components/MultiListener.tsx","../src/components/IsolatedContainer.tsx"],"names":["isObjectOrArray","value","isArray","isFunction","NotifierRoot","state","RootNode","Node","callback","listener","child","prevState","newState","key","index","prevChildState","_","prop","childNode","ChildNode","root","fromChild","parent","parentState","newParentState","functionCannotBeNotifierMessage","notifier","initialState","createNotifier","unsubscribe","multiListener","notifiers","unsubscribeFns","fn","useNotifier","useState","useListener","selector","areStatesEqual","useRef","useSyncExternalStore","nextState","areStatesEqualFn","prevValue","nextValue","useMultiListener","subscribe","useCallback","getSnapshot","ListenerComponent","stableChild","children","Listener","memo","prevProps","nextProps","MultiListenerComponent","MultiListener","IsolatedContainerComponent","jsx","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,QAAA,CAAAT,CAAAA,CAAS,CACvB,CAwBO,IAAMU,CAAAA,CAAoBR,UAAAA,CAC7BK,CAAAA,CACA,IAAM,IACV","file":"index.cjs","sourcesContent":["export function isObjectOrArray(value: unknown): value is object {\r\n return typeof value === \"object\" && value !== null;\r\n}\r\n\r\nexport function isArray(value: unknown): value is Array<unknown> {\r\n return Array.isArray(value);\r\n}\r\n\r\nexport function isFunction(value: unknown): value is Function {\r\n return typeof value === \"function\";\r\n}","import type {\r\n NodeKey,\r\n SetState,\r\n StateUpdater,\r\n VoidCallback\r\n} from \"./types\";\r\nimport { isArray, isFunction, isObjectOrArray } from \"./utils/helpers\";\r\n\r\nexport class NotifierRoot {\r\n public state: unknown;\r\n public rootNode: RootNode;\r\n\r\n constructor(state: unknown) {\r\n this.state = state;\r\n this.rootNode = new RootNode(this);\r\n }\r\n}\r\n\r\nabstract class Node {\r\n protected cachedState: unknown;\r\n private listeners: Set<VoidCallback>;\r\n private children: Map<NodeKey, ChildNode>;\r\n public proxy: object;\r\n\r\n constructor() {\r\n this.cachedState = null;\r\n this.listeners = new Set();\r\n this.children = new Map();\r\n this.proxy = this.createProxy();\r\n }\r\n\r\n public abstract get(): unknown;\r\n public abstract set(state: SetState<unknown>, fromChild: boolean): boolean;\r\n\r\n public dispatchSet = (state: SetState<unknown>) => {\r\n return this.set(state, false);\r\n };\r\n\r\n private subscribe = (callback: VoidCallback) => {\r\n this.listeners.add(callback);\r\n return () => {\r\n this.listeners.delete(callback);\r\n };\r\n };\r\n\r\n protected notifyListeners() {\r\n this.listeners.forEach((listener) => listener());\r\n }\r\n\r\n private notifySubtree() {\r\n this.cachedState = null;\r\n this.notifyListeners();\r\n for (const child of this.children.values()) {\r\n child.notifySubtree();\r\n }\r\n }\r\n\r\n protected reconcileChildren(prevState: unknown, newState: unknown) {\r\n if (!isArray(prevState) || !isArray(newState)) {\r\n return;\r\n }\r\n for (const [key, child] of this.children) {\r\n const index = key as `${number}`;\r\n const prevChildState = prevState[index];\r\n const newChildState = newState[index];\r\n if (newChildState !== prevChildState) {\r\n child.notifySubtree();\r\n }\r\n }\r\n }\r\n\r\n private setTrap() { return false; }\r\n\r\n private createProxy() {\r\n return new Proxy(\r\n {},\r\n {\r\n get: (_, prop) => {\r\n if (prop === \"get\") return this.get;\r\n if (prop === \"set\") return this.dispatchSet;\r\n if (prop === \"subscribe\") return this.subscribe;\r\n\r\n const state = this.get();\r\n if (isObjectOrArray(state) && prop in state) {\r\n const value = (state as any)[prop];\r\n if (isFunction(value)) return value;\r\n\r\n let childNode = this.children.get(prop);\r\n if (!childNode) {\r\n childNode = new ChildNode(prop, this);\r\n this.children.set(prop, childNode);\r\n }\r\n return childNode.proxy;\r\n }\r\n },\r\n set: this.setTrap\r\n }\r\n );\r\n }\r\n}\r\n\r\nclass RootNode extends Node {\r\n private root: NotifierRoot;\r\n\r\n constructor(root: NotifierRoot) {\r\n super();\r\n this.root = root;\r\n }\r\n\r\n public get = () => this.root.state;\r\n\r\n public set(state: SetState<unknown>, fromChild: boolean) {\r\n const prevState = this.get();\r\n const newState = isFunction(state)\r\n ? (state as StateUpdater<unknown>)(prevState)\r\n : state;\r\n if (newState !== prevState) {\r\n this.root.state = newState;\r\n this.notifyListeners();\r\n if (!fromChild) {\r\n this.reconcileChildren(prevState, newState);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n}\r\n\r\nclass ChildNode extends Node {\r\n private key: NodeKey;\r\n private parent: Node;\r\n\r\n constructor(key: NodeKey, parent: Node) {\r\n super();\r\n this.key = key;\r\n this.parent = parent;\r\n }\r\n\r\n public get = (): unknown => {\r\n if (this.cachedState !== null) {\r\n return this.cachedState;\r\n }\r\n const state = (this.parent.get() as any)[this.key];\r\n this.cachedState = state;\r\n return state;\r\n }\r\n\r\n public set(state: SetState<unknown>, fromChild: boolean) {\r\n const parentState = this.parent.get();\r\n const prevState = (parentState as any)[this.key];\r\n const newState = isFunction(state)\r\n ? (state as StateUpdater<unknown>)(prevState)\r\n : state;\r\n if (newState !== prevState) {\r\n const newParentState = Object.assign(\r\n isArray(parentState) ? [] : {},\r\n parentState\r\n );\r\n (newParentState as any)[this.key] = newState;\r\n const isSet = this.parent.set(newParentState, true);\r\n if (isSet) {\r\n this.cachedState = newState;\r\n this.notifyListeners();\r\n if (!fromChild) {\r\n this.reconcileChildren(prevState, newState);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n return false;\r\n }\r\n}","import { isFunction } from \"./helpers\";\r\nimport { NotifierRoot } from \"../notifier\";\r\nimport type { InitialState, Notifier } from \"../types\";\r\n\r\nconst functionCannotBeNotifierMessage =\r\n \"A function cannot be a notifier. Replace it with other value, or add it as a property/method inside an object, or don't wrap it with notifier.\";\r\n\r\n/**\r\n * Creates a core, global root-level state container wrapped in a deeply reactive proxy tree.\r\n * \r\n * @remarks\r\n * Serves as the primary entry point for global stores outside of React. Every nested property \r\n * automatically becomes a sub-notifier. Raw functions cannot be notifiers and will throw an error.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/notifier.md)\r\n * \r\n * @template T The shape of the initial state.\r\n * @param initialState The initial value of the state, or a lazy initialization function returning the state.\r\n * @returns A root Notifier proxy instance.\r\n * \r\n * @example\r\n * ```ts\r\n * import { notifier } from \"barrex\";\r\n * \r\n * const authNotifier = notifier({\r\n * user: null,\r\n * isAuthenticated: false\r\n * });\r\n * ```\r\n */\r\nexport function notifier<T>(initialState: InitialState<T>): Notifier<T> {\r\n const state = (isFunction(initialState)\r\n ? (initialState as () => T)()\r\n : initialState) as T;\r\n if (isFunction(state)) {\r\n throw new Error(functionCannotBeNotifierMessage);\r\n }\r\n return createNotifier(state);\r\n}\r\n\r\nfunction createNotifier<T>(state: T): Notifier<T> {\r\n const root = new NotifierRoot(state);\r\n return root.rootNode.proxy as Notifier<T>;\r\n}","import type { ListenerCallback, Notifier, VoidCallback } from \"../types\";\r\n\r\n/**\r\n * Subscribes imperatively to a `barrex` notifier outside of React component trees.\r\n * \r\n * @remarks\r\n * Executes the callback immediately upon registration with the current state value, \r\n * and subsequently every time the notifier updates. Returns a cleanup function to unsubscribe.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/listener.md)\r\n * \r\n * @param notifier The source notifier instance to subscribe to.\r\n * @param callback A callback function invoked immediately and on every state update.\r\n * @returns A cleanup function to remove the subscription.\r\n * \r\n * @example\r\n * ```ts\r\n * import { listener } from \"barrex\";\r\n * \r\n * const unsubscribe = listener(themeNotifier, (theme) => {\r\n * localStorage.setItem(\"theme\", theme);\r\n * });\r\n * ```\r\n */\r\nexport function listener<T>(\r\n notifier: Notifier<T>,\r\n callback: ListenerCallback<T>\r\n): VoidCallback {\r\n const unsubscribe = notifier.subscribe(() => {\r\n callback(notifier.get());\r\n });\r\n callback(notifier.get());\r\n return unsubscribe;\r\n}","import type {\r\n InferNotifierValues,\r\n ListenerCallback,\r\n Notifier,\r\n VoidCallback\r\n} from \"../types\";\r\n\r\n/**\r\n * Subscribes imperatively to multiple `barrex` notifiers simultaneously outside of React.\r\n * \r\n * @remarks\r\n * Accepts a tuple array of notifiers, infers their types automatically, executes \r\n * the callback immediately with the initial values tuple, and returns a single composite cleanup function.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/multi-listener.md)\r\n * \r\n * @param notifiers A readonly tuple array of source notifiers to subscribe to.\r\n * @param callback A callback function invoked immediately with the values tuple and on subsequent updates.\r\n * @returns A composite cleanup function to unsubscribe from all provided notifiers.\r\n * \r\n * @example\r\n * ```ts\r\n * import { multiListener } from \"barrex\";\r\n * \r\n * const unsubscribe = multiListener(\r\n * [userNotifier.name, settingsNotifier.theme],\r\n * ([name, theme]) => {\r\n * console.log(`User: ${name}, Theme: ${theme}`);\r\n * }\r\n * );\r\n * ```\r\n */\r\nexport function multiListener<\r\n const T extends readonly Notifier<unknown>[]\r\n>(\r\n notifiers: T,\r\n callback: ListenerCallback<InferNotifierValues<T>>\r\n): VoidCallback {\r\n const listener = () => {\r\n const state = notifiers.map((notifier) => notifier.get()) as any;\r\n callback(state);\r\n };\r\n const unsubscribeFns = notifiers.map((notifier) => {\r\n return notifier.subscribe(listener);\r\n });\r\n const unsubscribe = () => unsubscribeFns.forEach((fn) => fn());\r\n listener();\r\n return unsubscribe;\r\n}","import { useState } from \"react\";\r\n\r\nimport type { InitialState, Notifier } from \"../types\";\r\nimport { notifier as createNotifier } from \"../utils/notifier\";\r\n\r\n/**\r\n * Creates a component-scoped, lazy-initialized notifier with automatic \r\n * proxy-driven nested reactivity.\r\n * \r\n * @remarks\r\n * Tied directly to the component lifecycle. Every property on the initial state \r\n * object automatically becomes a first-class sub-notifier.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-notifier.md)\r\n * \r\n * @template T The shape of the initial state.\r\n * @param initialState The initial value or a lazy initializer function returning the state.\r\n * @returns A root Notifier proxy instance.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useNotifier, useListener } from \"barrex\";\r\n * \r\n * function Profile() {\r\n * const userNotifier = useNotifier({ name: \"Alice\", age: 40 });\r\n * const name = useListener(userNotifier.name);\r\n * return <p>{name}</p>;\r\n * }\r\n * ```\r\n */\r\nexport function useNotifier<T>(initialState: InitialState<T>): Notifier<T> {\r\n const [notifier] = useState(() => createNotifier(initialState));\r\n return notifier;\r\n}","import { useRef, useSyncExternalStore } from \"react\";\r\n\r\nimport type { Notifier, StatesComparer, StateSelector } from \"../types\";\r\n\r\n/**\r\n * Subscribes a React component to a `barrex` notifier, enabling precise, \r\n * fine-grained reactivity using `useSyncExternalStore`.\r\n * \r\n * @remarks\r\n * Components re-render only when the exact state slice or computed selector \r\n * value updates, preventing unnecessary re-renders across the tree.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-listener.md)\r\n * \r\n * @template T The raw type of the source notifier state.\r\n * @template U The resolved type after applying the selector.\r\n * \r\n * @param notifier The source notifier instance to subscribe to.\r\n * @param selector Optional function to transform or compute a specific slice from the notifier state.\r\n * @param areStatesEqual Optional custom comparer. Returns true to reuse the previous state reference and skip re-renders.\r\n * @returns The current resolved state (raw or selected).\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useListener } from \"barrex\";\r\n * \r\n * function Counter() {\r\n * const count = useListener(counterNotifier.count);\r\n * return <span>Count: {count}</span>;\r\n * }\r\n * ```\r\n */\r\nexport function useListener<T, U = T>(\r\n notifier: Notifier<T>,\r\n selector?: StateSelector<T, U>,\r\n areStatesEqual?: StatesComparer<U>\r\n): U {\r\n const prevState = useRef<U>(null);\r\n\r\n return useSyncExternalStore(\r\n notifier.subscribe,\r\n () => {\r\n const nextState = selector\r\n ? selector(notifier.get())\r\n : notifier.get() as unknown as U;\r\n if (areStatesEqual && prevState.current !== null) {\r\n const areEqual = areStatesEqual(prevState.current, nextState);\r\n if (areEqual) return prevState.current;\r\n }\r\n prevState.current = nextState;\r\n return nextState;\r\n },\r\n () => (selector ? selector(notifier.get()) : notifier.get() as unknown as U)\r\n );\r\n}","import { useCallback, useRef, useSyncExternalStore } from \"react\";\r\n\r\nimport type {\r\n InferNotifierValues,\r\n Notifier,\r\n StatesComparer,\r\n StateSelector,\r\n VoidCallback\r\n} from \"../types\";\r\nimport { isArray } from \"../utils/helpers\";\r\n\r\nfunction areStatesEqualFn<T>(prevState: T, nextState: T) {\r\n if (\r\n isArray(prevState) &&\r\n isArray(nextState) &&\r\n prevState.length === nextState.length\r\n ) {\r\n return prevState.every((prevValue, index) => {\r\n const nextValue = nextState[index];\r\n return prevValue === nextValue;\r\n });\r\n }\r\n return prevState === nextState;\r\n};\r\n\r\n/**\r\n * Subscribes a React component to multiple notifiers simultaneously, \r\n * offering complete type safety and optimized derivations.\r\n * \r\n * @remarks\r\n * Bundles multiple notifier subscriptions into a single unified cleanup routine \r\n * and includes smart array/tuple shallow comparison by default.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-multi-listener.md)\r\n * \r\n * @param notifiers A readonly tuple array of source notifiers to subscribe to.\r\n * @param selector Optional function to transform or combine the tuple values into a custom shape.\r\n * @param areStatesEqual Optional custom comparator. Defaults to a smart tuple-aware shallow equality checker.\r\n * @returns The resolved state tuple or the computed selector output.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useMultiListener } from \"barrex\";\r\n * \r\n * function Header() {\r\n * const [name, theme] = useMultiListener([userNotifier.name, themeNotifier]);\r\n * return <header className={theme}>Welcome, {name}</header>;\r\n * }\r\n * ```\r\n */\r\nexport function useMultiListener<\r\n const T extends readonly Notifier<unknown>[],\r\n const U\r\n>(\r\n notifiers: T,\r\n selector: StateSelector<InferNotifierValues<T>, U>,\r\n areStatesEqual?: StatesComparer<U>\r\n): U;\r\n\r\nexport function useMultiListener<\r\n const T extends readonly Notifier<unknown>[]\r\n>(\r\n notifiers: T,\r\n selector?: undefined,\r\n areStatesEqual?: StatesComparer<InferNotifierValues<T>>\r\n): InferNotifierValues<T>;\r\n\r\nexport function useMultiListener(\r\n notifiers: Notifier<unknown>[],\r\n selector?: StateSelector<any, any>,\r\n areStatesEqual: StatesComparer<any> = areStatesEqualFn\r\n): unknown {\r\n const prevState = useRef<unknown>(null);\r\n\r\n const subscribe = useCallback((callback: VoidCallback) => {\r\n const unsubscribeFns = notifiers.map((notifier) => {\r\n return notifier.subscribe(callback);\r\n });\r\n return () => unsubscribeFns.forEach((fn) => fn());\r\n }, notifiers);\r\n\r\n const getSnapshot = () => {\r\n const state = notifiers.map((notifier) => notifier.get());\r\n const nextState = selector ? selector(state) : state;\r\n if (prevState.current !== null) {\r\n const areEqual = areStatesEqual(prevState.current, nextState);\r\n if (areEqual) return prevState.current;\r\n }\r\n prevState.current = nextState;\r\n return nextState;\r\n };\r\n\r\n return useSyncExternalStore(\r\n subscribe,\r\n getSnapshot,\r\n getSnapshot\r\n );\r\n}","import { memo } from \"react\";\r\n\r\nimport type { ListenerProps } from \"../types\";\r\nimport { useListener } from \"../hooks/useListener\";\r\n\r\nfunction ListenerComponent<T, U = T>({\r\n notifier,\r\n selector,\r\n areStatesEqual,\r\n stableChild,\r\n children\r\n}: ListenerProps<T, U>) {\r\n const state = useListener(notifier, selector, areStatesEqual);\r\n return children(state, stableChild);\r\n}\r\n\r\n/**\r\n * A declarative component wrapper that brings fine-grained reactivity \r\n * and granular performance optimization directly into your JSX tree.\r\n * \r\n * @remarks\r\n * Confines updates strictly to its render-prop children without forcing \r\n * an entire component function to re-render.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/listener.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { Listener } from \"barrex\";\r\n * \r\n * <Listener notifier={userNotifier.name}>\r\n * {(name) => <h1>Welcome, {name}!</h1>}\r\n * </Listener>\r\n * ```\r\n */\r\nexport const Listener = memo(\r\n ListenerComponent,\r\n (prevProps, nextProps) => {\r\n if (nextProps.isolated) return true;\r\n return (\r\n prevProps.notifier === nextProps.notifier &&\r\n prevProps.selector === nextProps.selector &&\r\n prevProps.areStatesEqual === nextProps.areStatesEqual &&\r\n prevProps.stableChild === nextProps.stableChild &&\r\n prevProps.children === nextProps.children\r\n );\r\n }\r\n) as typeof ListenerComponent;","import { memo } from \"react\";\r\n\r\nimport { useMultiListener } from \"../hooks/useMultiListener\";\r\nimport type { MultiListenerComponent as MultiListenerComponentType } from \"../types\";\r\n\r\nfunction MultiListenerComponent({\r\n notifiers,\r\n selector,\r\n areStatesEqual,\r\n stableChild,\r\n children\r\n}: any) {\r\n const state = useMultiListener(notifiers, selector, areStatesEqual);\r\n return children(state, stableChild);\r\n}\r\n\r\n/**\r\n * An advanced declarative component wrapper that enables fine-grained \r\n * subscriptions to multiple notifiers simultaneously with full type safety.\r\n * \r\n * @remarks\r\n * Automatically infers tuple types from the provided notifiers array \r\n * and includes smart array equality checking.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/multi-listener.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { MultiListener } from \"barrex\";\r\n * \r\n * <MultiListener notifiers={[userNotifier.name, cartNotifier.count]}>\r\n * {([name, count]) => <p>{name} has {count} items</p>}\r\n * </MultiListener>\r\n * ```\r\n */\r\nexport const MultiListener: MultiListenerComponentType = memo(\r\n MultiListenerComponent,\r\n (prevProps, nextProps) => {\r\n if (nextProps.isolated) return true;\r\n return (\r\n prevProps.notifiers === nextProps.notifiers &&\r\n prevProps.selector === nextProps.selector &&\r\n prevProps.areStatesEqual === nextProps.areStatesEqual &&\r\n prevProps.stableChild === nextProps.stableChild &&\r\n prevProps.children === nextProps.children\r\n );\r\n }\r\n);","import { memo } from \"react\";\r\n\r\nimport type { IsolatedContainerProps } from \"../types\";\r\n\r\nfunction IsolatedContainerComponent({ children }: IsolatedContainerProps) {\r\n return <>{children}</>;\r\n}\r\n\r\n/**\r\n * A boundary component designed to completely shield its child \r\n * subtree from parent-driven re-render cascades.\r\n * \r\n * @remarks\r\n * Children inside an `IsolatedContainer` can still re-render independently \r\n * based on their own local state or external reactive bindings (like `barrex` notifiers).\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/isolated-container.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { IsolatedContainer } from \"barrex\";\r\n * \r\n * <IsolatedContainer>\r\n * <StaticHeader/>\r\n * <CounterWidget/>\r\n * </IsolatedContainer>\r\n * ```\r\n */\r\nexport const IsolatedContainer = memo(\r\n IsolatedContainerComponent,\r\n () => true\r\n) as typeof IsolatedContainerComponent;"]}
package/dist/index.d.cts CHANGED
@@ -130,7 +130,7 @@ type InferNotifierValues<T extends readonly Notifier<unknown>[]> = {
130
130
  * Serves as the primary entry point for global stores outside of React. Every nested property
131
131
  * automatically becomes a sub-notifier. Raw functions cannot be notifiers and will throw an error.
132
132
  *
133
- * @see [Barrex Docs](./docs/utils/notifier.md)
133
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/notifier.md)
134
134
  *
135
135
  * @template T The shape of the initial state.
136
136
  * @param initialState The initial value of the state, or a lazy initialization function returning the state.
@@ -155,7 +155,7 @@ declare function notifier<T>(initialState: InitialState<T>): Notifier<T>;
155
155
  * Executes the callback immediately upon registration with the current state value,
156
156
  * and subsequently every time the notifier updates. Returns a cleanup function to unsubscribe.
157
157
  *
158
- * @see [Barrex Docs](./docs/utils/listener.md)
158
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/listener.md)
159
159
  *
160
160
  * @param notifier The source notifier instance to subscribe to.
161
161
  * @param callback A callback function invoked immediately and on every state update.
@@ -179,7 +179,7 @@ declare function listener<T>(notifier: Notifier<T>, callback: ListenerCallback<T
179
179
  * Accepts a tuple array of notifiers, infers their types automatically, executes
180
180
  * the callback immediately with the initial values tuple, and returns a single composite cleanup function.
181
181
  *
182
- * @see [Barrex Docs](./docs/utils/multi-listener.md)
182
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/multi-listener.md)
183
183
  *
184
184
  * @param notifiers A readonly tuple array of source notifiers to subscribe to.
185
185
  * @param callback A callback function invoked immediately with the values tuple and on subsequent updates.
@@ -207,7 +207,7 @@ declare function multiListener<const T extends readonly Notifier<unknown>[]>(not
207
207
  * Tied directly to the component lifecycle. Every property on the initial state
208
208
  * object automatically becomes a first-class sub-notifier.
209
209
  *
210
- * @see [Barrex Docs](./docs/hooks/use-notifier.md)
210
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-notifier.md)
211
211
  *
212
212
  * @template T The shape of the initial state.
213
213
  * @param initialState The initial value or a lazy initializer function returning the state.
@@ -234,7 +234,7 @@ declare function useNotifier<T>(initialState: InitialState<T>): Notifier<T>;
234
234
  * Components re-render only when the exact state slice or computed selector
235
235
  * value updates, preventing unnecessary re-renders across the tree.
236
236
  *
237
- * @see [Barrex Docs](./docs/hooks/use-listener.md)
237
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-listener.md)
238
238
  *
239
239
  * @template T The raw type of the source notifier state.
240
240
  * @template U The resolved type after applying the selector.
@@ -249,7 +249,7 @@ declare function useNotifier<T>(initialState: InitialState<T>): Notifier<T>;
249
249
  * import { useListener } from "barrex";
250
250
  *
251
251
  * function Counter() {
252
- * const count = useListener(counterNotifier);
252
+ * const count = useListener(counterNotifier.count);
253
253
  * return <span>Count: {count}</span>;
254
254
  * }
255
255
  * ```
@@ -264,7 +264,7 @@ declare function useListener<T, U = T>(notifier: Notifier<T>, selector?: StateSe
264
264
  * Bundles multiple notifier subscriptions into a single unified cleanup routine
265
265
  * and includes smart array/tuple shallow comparison by default.
266
266
  *
267
- * @see [Barrex Docs](./docs/hooks/use-multi-listener.md)
267
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-multi-listener.md)
268
268
  *
269
269
  * @param notifiers A readonly tuple array of source notifiers to subscribe to.
270
270
  * @param selector Optional function to transform or combine the tuple values into a custom shape.
@@ -293,7 +293,7 @@ declare function ListenerComponent<T, U = T>({ notifier, selector, areStatesEqua
293
293
  * Confines updates strictly to its render-prop children without forcing
294
294
  * an entire component function to re-render.
295
295
  *
296
- * @see [Barrex Docs](./docs/components/listener.md)
296
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/listener.md)
297
297
  *
298
298
  * @param props The component props.
299
299
  *
@@ -316,7 +316,7 @@ declare const Listener: typeof ListenerComponent;
316
316
  * Automatically infers tuple types from the provided notifiers array
317
317
  * and includes smart array equality checking.
318
318
  *
319
- * @see [Barrex Docs](./docs/components/multi-listener.md)
319
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/multi-listener.md)
320
320
  *
321
321
  * @param props The component props.
322
322
  *
@@ -340,7 +340,7 @@ declare function IsolatedContainerComponent({ children }: IsolatedContainerProps
340
340
  * Children inside an `IsolatedContainer` can still re-render independently
341
341
  * based on their own local state or external reactive bindings (like `barrex` notifiers).
342
342
  *
343
- * @see [Barrex Docs](./docs/components/isolated-container.md)
343
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/isolated-container.md)
344
344
  *
345
345
  * @param props The component props.
346
346
  *
package/dist/index.d.ts CHANGED
@@ -130,7 +130,7 @@ type InferNotifierValues<T extends readonly Notifier<unknown>[]> = {
130
130
  * Serves as the primary entry point for global stores outside of React. Every nested property
131
131
  * automatically becomes a sub-notifier. Raw functions cannot be notifiers and will throw an error.
132
132
  *
133
- * @see [Barrex Docs](./docs/utils/notifier.md)
133
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/notifier.md)
134
134
  *
135
135
  * @template T The shape of the initial state.
136
136
  * @param initialState The initial value of the state, or a lazy initialization function returning the state.
@@ -155,7 +155,7 @@ declare function notifier<T>(initialState: InitialState<T>): Notifier<T>;
155
155
  * Executes the callback immediately upon registration with the current state value,
156
156
  * and subsequently every time the notifier updates. Returns a cleanup function to unsubscribe.
157
157
  *
158
- * @see [Barrex Docs](./docs/utils/listener.md)
158
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/listener.md)
159
159
  *
160
160
  * @param notifier The source notifier instance to subscribe to.
161
161
  * @param callback A callback function invoked immediately and on every state update.
@@ -179,7 +179,7 @@ declare function listener<T>(notifier: Notifier<T>, callback: ListenerCallback<T
179
179
  * Accepts a tuple array of notifiers, infers their types automatically, executes
180
180
  * the callback immediately with the initial values tuple, and returns a single composite cleanup function.
181
181
  *
182
- * @see [Barrex Docs](./docs/utils/multi-listener.md)
182
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/multi-listener.md)
183
183
  *
184
184
  * @param notifiers A readonly tuple array of source notifiers to subscribe to.
185
185
  * @param callback A callback function invoked immediately with the values tuple and on subsequent updates.
@@ -207,7 +207,7 @@ declare function multiListener<const T extends readonly Notifier<unknown>[]>(not
207
207
  * Tied directly to the component lifecycle. Every property on the initial state
208
208
  * object automatically becomes a first-class sub-notifier.
209
209
  *
210
- * @see [Barrex Docs](./docs/hooks/use-notifier.md)
210
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-notifier.md)
211
211
  *
212
212
  * @template T The shape of the initial state.
213
213
  * @param initialState The initial value or a lazy initializer function returning the state.
@@ -234,7 +234,7 @@ declare function useNotifier<T>(initialState: InitialState<T>): Notifier<T>;
234
234
  * Components re-render only when the exact state slice or computed selector
235
235
  * value updates, preventing unnecessary re-renders across the tree.
236
236
  *
237
- * @see [Barrex Docs](./docs/hooks/use-listener.md)
237
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-listener.md)
238
238
  *
239
239
  * @template T The raw type of the source notifier state.
240
240
  * @template U The resolved type after applying the selector.
@@ -249,7 +249,7 @@ declare function useNotifier<T>(initialState: InitialState<T>): Notifier<T>;
249
249
  * import { useListener } from "barrex";
250
250
  *
251
251
  * function Counter() {
252
- * const count = useListener(counterNotifier);
252
+ * const count = useListener(counterNotifier.count);
253
253
  * return <span>Count: {count}</span>;
254
254
  * }
255
255
  * ```
@@ -264,7 +264,7 @@ declare function useListener<T, U = T>(notifier: Notifier<T>, selector?: StateSe
264
264
  * Bundles multiple notifier subscriptions into a single unified cleanup routine
265
265
  * and includes smart array/tuple shallow comparison by default.
266
266
  *
267
- * @see [Barrex Docs](./docs/hooks/use-multi-listener.md)
267
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-multi-listener.md)
268
268
  *
269
269
  * @param notifiers A readonly tuple array of source notifiers to subscribe to.
270
270
  * @param selector Optional function to transform or combine the tuple values into a custom shape.
@@ -293,7 +293,7 @@ declare function ListenerComponent<T, U = T>({ notifier, selector, areStatesEqua
293
293
  * Confines updates strictly to its render-prop children without forcing
294
294
  * an entire component function to re-render.
295
295
  *
296
- * @see [Barrex Docs](./docs/components/listener.md)
296
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/listener.md)
297
297
  *
298
298
  * @param props The component props.
299
299
  *
@@ -316,7 +316,7 @@ declare const Listener: typeof ListenerComponent;
316
316
  * Automatically infers tuple types from the provided notifiers array
317
317
  * and includes smart array equality checking.
318
318
  *
319
- * @see [Barrex Docs](./docs/components/multi-listener.md)
319
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/multi-listener.md)
320
320
  *
321
321
  * @param props The component props.
322
322
  *
@@ -340,7 +340,7 @@ declare function IsolatedContainerComponent({ children }: IsolatedContainerProps
340
340
  * Children inside an `IsolatedContainer` can still re-render independently
341
341
  * based on their own local state or external reactive bindings (like `barrex` notifiers).
342
342
  *
343
- * @see [Barrex Docs](./docs/components/isolated-container.md)
343
+ * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/isolated-container.md)
344
344
  *
345
345
  * @param props The component props.
346
346
  *
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/helpers.ts","../src/notifier.ts","../src/utils/notifier.ts","../src/utils/listener.ts","../src/utils/multi-listener.ts","../src/hooks/useNotifier.ts","../src/hooks/useListener.ts","../src/hooks/useMultiListener.ts","../src/components/Listener.tsx","../src/components/MultiListener.tsx","../src/components/IsolatedContainer.tsx"],"names":["isObjectOrArray","value","isArray","isFunction","NotifierRoot","state","RootNode","Node","callback","listener","child","prevState","newState","key","index","prevChildState","_","prop","childNode","ChildNode","root","fromChild","parent","parentState","newParentState","functionCannotBeNotifierMessage","notifier","initialState","createNotifier","unsubscribe","multiListener","notifiers","unsubscribeFns","fn","useNotifier","useState","useListener","selector","areStatesEqual","useRef","useSyncExternalStore","nextState","areStatesEqualFn","prevValue","nextValue","useMultiListener","subscribe","useCallback","getSnapshot","ListenerComponent","stableChild","children","Listener","memo","prevProps","nextProps","MultiListenerComponent","MultiListener","IsolatedContainerComponent","jsx","Fragment","IsolatedContainer"],"mappings":"uHAAO,SAASA,CAAAA,CAAgBC,CAAAA,CAAiC,CAC7D,OAAO,OAAOA,GAAU,QAAA,EAAYA,CAAAA,GAAU,IAClD,CAEO,SAASC,CAAAA,CAAQD,EAAyC,CAC7D,OAAO,KAAA,CAAM,OAAA,CAAQA,CAAK,CAC9B,CAEO,SAASE,CAAAA,CAAWF,CAAAA,CAAmC,CAC1D,OAAO,OAAOA,GAAU,UAC5B,CCFO,IAAMG,CAAAA,CAAN,KAAmB,CACf,MACA,QAAA,CAEP,WAAA,CAAYC,CAAAA,CAAgB,CACxB,IAAA,CAAK,KAAA,CAAQA,EACb,IAAA,CAAK,QAAA,CAAW,IAAIC,CAAAA,CAAS,IAAI,EACrC,CACJ,CAAA,CAEeC,CAAAA,CAAf,KAAoB,CACN,WAAA,CACF,SAAA,CACA,SACD,KAAA,CAEP,WAAA,EAAc,CACV,IAAA,CAAK,WAAA,CAAc,IAAA,CACnB,KAAK,SAAA,CAAY,IAAI,GAAA,CACrB,IAAA,CAAK,QAAA,CAAW,IAAI,IACpB,IAAA,CAAK,KAAA,CAAQ,IAAA,CAAK,WAAA,GACtB,CAKO,YAAeF,CAAAA,EACX,IAAA,CAAK,GAAA,CAAIA,CAAAA,CAAO,KAAK,CAAA,CAGxB,UAAaG,CAAAA,GACjB,IAAA,CAAK,SAAA,CAAU,GAAA,CAAIA,CAAQ,CAAA,CACpB,IAAM,CACT,IAAA,CAAK,SAAA,CAAU,MAAA,CAAOA,CAAQ,EAClC,GAGM,eAAA,EAAkB,CACxB,IAAA,CAAK,SAAA,CAAU,OAAA,CAASC,CAAAA,EAAaA,GAAU,EACnD,CAEQ,aAAA,EAAgB,CACpB,IAAA,CAAK,YAAc,IAAA,CACnB,IAAA,CAAK,eAAA,EAAgB,CACrB,IAAA,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,SAASG,CAAAA,CAA2B,CAAE,QAAA,CAAAP,CAAS,CAAA,CAA2B,CACtE,OAAOQ,GAAAA,CAAAC,QAAAA,CAAA,CAAG,QAAA,CAAAT,CAAAA,CAAS,CACvB,CAwBO,IAAMU,CAAAA,CAAoBR,IAAAA,CAC7BK,CAAAA,CACA,IAAM,IACV","file":"index.js","sourcesContent":["export function isObjectOrArray(value: unknown): value is object {\r\n return typeof value === \"object\" && value !== null;\r\n}\r\n\r\nexport function isArray(value: unknown): value is Array<unknown> {\r\n return Array.isArray(value);\r\n}\r\n\r\nexport function isFunction(value: unknown): value is Function {\r\n return typeof value === \"function\";\r\n}","import type {\r\n NodeKey,\r\n SetState,\r\n StateUpdater,\r\n VoidCallback\r\n} from \"./types\";\r\nimport { isArray, isFunction, isObjectOrArray } from \"./utils/helpers\";\r\n\r\nexport class NotifierRoot {\r\n public state: unknown;\r\n public rootNode: RootNode;\r\n\r\n constructor(state: unknown) {\r\n this.state = state;\r\n this.rootNode = new RootNode(this);\r\n }\r\n}\r\n\r\nabstract class Node {\r\n protected cachedState: unknown;\r\n private listeners: Set<VoidCallback>;\r\n private children: Map<NodeKey, ChildNode>;\r\n public proxy: object;\r\n\r\n constructor() {\r\n this.cachedState = null;\r\n this.listeners = new Set();\r\n this.children = new Map();\r\n this.proxy = this.createProxy();\r\n }\r\n\r\n public abstract get(): unknown;\r\n public abstract set(state: SetState<unknown>, fromChild: boolean): boolean;\r\n\r\n public dispatchSet = (state: SetState<unknown>) => {\r\n return this.set(state, false);\r\n };\r\n\r\n private subscribe = (callback: VoidCallback) => {\r\n this.listeners.add(callback);\r\n return () => {\r\n this.listeners.delete(callback);\r\n };\r\n };\r\n\r\n protected notifyListeners() {\r\n this.listeners.forEach((listener) => listener());\r\n }\r\n\r\n private notifySubtree() {\r\n this.cachedState = null;\r\n this.notifyListeners();\r\n for (const child of this.children.values()) {\r\n child.notifySubtree();\r\n }\r\n }\r\n\r\n protected reconcileChildren(prevState: unknown, newState: unknown) {\r\n if (!isArray(prevState) || !isArray(newState)) {\r\n return;\r\n }\r\n for (const [key, child] of this.children) {\r\n const index = key as `${number}`;\r\n const prevChildState = prevState[index];\r\n const newChildState = newState[index];\r\n if (newChildState !== prevChildState) {\r\n child.notifySubtree();\r\n }\r\n }\r\n }\r\n\r\n private setTrap() { return false; }\r\n\r\n private createProxy() {\r\n return new Proxy(\r\n {},\r\n {\r\n get: (_, prop) => {\r\n if (prop === \"get\") return this.get;\r\n if (prop === \"set\") return this.dispatchSet;\r\n if (prop === \"subscribe\") return this.subscribe;\r\n\r\n const state = this.get();\r\n if (isObjectOrArray(state) && prop in state) {\r\n const value = (state as any)[prop];\r\n if (isFunction(value)) return value;\r\n\r\n let childNode = this.children.get(prop);\r\n if (!childNode) {\r\n childNode = new ChildNode(prop, this);\r\n this.children.set(prop, childNode);\r\n }\r\n return childNode.proxy;\r\n }\r\n },\r\n set: this.setTrap\r\n }\r\n );\r\n }\r\n}\r\n\r\nclass RootNode extends Node {\r\n private root: NotifierRoot;\r\n\r\n constructor(root: NotifierRoot) {\r\n super();\r\n this.root = root;\r\n }\r\n\r\n public get = () => this.root.state;\r\n\r\n public set(state: SetState<unknown>, fromChild: boolean) {\r\n const prevState = this.get();\r\n const newState = isFunction(state)\r\n ? (state as StateUpdater<unknown>)(prevState)\r\n : state;\r\n if (newState !== prevState) {\r\n this.root.state = newState;\r\n this.notifyListeners();\r\n if (!fromChild) {\r\n this.reconcileChildren(prevState, newState);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n}\r\n\r\nclass ChildNode extends Node {\r\n private key: NodeKey;\r\n private parent: Node;\r\n\r\n constructor(key: NodeKey, parent: Node) {\r\n super();\r\n this.key = key;\r\n this.parent = parent;\r\n }\r\n\r\n public get = (): unknown => {\r\n if (this.cachedState !== null) {\r\n return this.cachedState;\r\n }\r\n const state = (this.parent.get() as any)[this.key];\r\n this.cachedState = state;\r\n return state;\r\n }\r\n\r\n public set(state: SetState<unknown>, fromChild: boolean) {\r\n const parentState = this.parent.get();\r\n const prevState = (parentState as any)[this.key];\r\n const newState = isFunction(state)\r\n ? (state as StateUpdater<unknown>)(prevState)\r\n : state;\r\n if (newState !== prevState) {\r\n const newParentState = Object.assign(\r\n isArray(parentState) ? [] : {},\r\n parentState\r\n );\r\n (newParentState as any)[this.key] = newState;\r\n const isSet = this.parent.set(newParentState, true);\r\n if (isSet) {\r\n this.cachedState = newState;\r\n this.notifyListeners();\r\n if (!fromChild) {\r\n this.reconcileChildren(prevState, newState);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n return false;\r\n }\r\n}","import { isFunction } from \"./helpers\";\r\nimport { NotifierRoot } from \"../notifier\";\r\nimport type { InitialState, Notifier } from \"../types\";\r\n\r\nconst functionCannotBeNotifierMessage =\r\n \"A function cannot be a notifier. Replace it with other value, or add it as a property/method inside an object, or don't wrap it with notifier.\";\r\n\r\n/**\r\n * Creates a core, global root-level state container wrapped in a deeply reactive proxy tree.\r\n * \r\n * @remarks\r\n * Serves as the primary entry point for global stores outside of React. Every nested property \r\n * automatically becomes a sub-notifier. Raw functions cannot be notifiers and will throw an error.\r\n * \r\n * @see [Barrex Docs](./docs/utils/notifier.md)\r\n * \r\n * @template T The shape of the initial state.\r\n * @param initialState The initial value of the state, or a lazy initialization function returning the state.\r\n * @returns A root Notifier proxy instance.\r\n * \r\n * @example\r\n * ```ts\r\n * import { notifier } from \"barrex\";\r\n * \r\n * const authNotifier = notifier({\r\n * user: null,\r\n * isAuthenticated: false\r\n * });\r\n * ```\r\n */\r\nexport function notifier<T>(initialState: InitialState<T>): Notifier<T> {\r\n const state = (isFunction(initialState)\r\n ? (initialState as () => T)()\r\n : initialState) as T;\r\n if (isFunction(state)) {\r\n throw new Error(functionCannotBeNotifierMessage);\r\n }\r\n return createNotifier(state);\r\n}\r\n\r\nfunction createNotifier<T>(state: T): Notifier<T> {\r\n const root = new NotifierRoot(state);\r\n return root.rootNode.proxy as Notifier<T>;\r\n}","import type { ListenerCallback, Notifier, VoidCallback } from \"../types\";\r\n\r\n/**\r\n * Subscribes imperatively to a `barrex` notifier outside of React component trees.\r\n * \r\n * @remarks\r\n * Executes the callback immediately upon registration with the current state value, \r\n * and subsequently every time the notifier updates. Returns a cleanup function to unsubscribe.\r\n * \r\n * @see [Barrex Docs](./docs/utils/listener.md)\r\n * \r\n * @param notifier The source notifier instance to subscribe to.\r\n * @param callback A callback function invoked immediately and on every state update.\r\n * @returns A cleanup function to remove the subscription.\r\n * \r\n * @example\r\n * ```ts\r\n * import { listener } from \"barrex\";\r\n * \r\n * const unsubscribe = listener(themeNotifier, (theme) => {\r\n * localStorage.setItem(\"theme\", theme);\r\n * });\r\n * ```\r\n */\r\nexport function listener<T>(\r\n notifier: Notifier<T>,\r\n callback: ListenerCallback<T>\r\n): VoidCallback {\r\n const unsubscribe = notifier.subscribe(() => {\r\n callback(notifier.get());\r\n });\r\n callback(notifier.get());\r\n return unsubscribe;\r\n}","import type {\r\n InferNotifierValues,\r\n ListenerCallback,\r\n Notifier,\r\n VoidCallback\r\n} from \"../types\";\r\n\r\n/**\r\n * Subscribes imperatively to multiple `barrex` notifiers simultaneously outside of React.\r\n * \r\n * @remarks\r\n * Accepts a tuple array of notifiers, infers their types automatically, executes \r\n * the callback immediately with the initial values tuple, and returns a single composite cleanup function.\r\n * \r\n * @see [Barrex Docs](./docs/utils/multi-listener.md)\r\n * \r\n * @param notifiers A readonly tuple array of source notifiers to subscribe to.\r\n * @param callback A callback function invoked immediately with the values tuple and on subsequent updates.\r\n * @returns A composite cleanup function to unsubscribe from all provided notifiers.\r\n * \r\n * @example\r\n * ```ts\r\n * import { multiListener } from \"barrex\";\r\n * \r\n * const unsubscribe = multiListener(\r\n * [userNotifier.name, settingsNotifier.theme],\r\n * ([name, theme]) => {\r\n * console.log(`User: ${name}, Theme: ${theme}`);\r\n * }\r\n * );\r\n * ```\r\n */\r\nexport function multiListener<\r\n const T extends readonly Notifier<unknown>[]\r\n>(\r\n notifiers: T,\r\n callback: ListenerCallback<InferNotifierValues<T>>\r\n): VoidCallback {\r\n const listener = () => {\r\n const state = notifiers.map((notifier) => notifier.get()) as any;\r\n callback(state);\r\n };\r\n const unsubscribeFns = notifiers.map((notifier) => {\r\n return notifier.subscribe(listener);\r\n });\r\n const unsubscribe = () => unsubscribeFns.forEach((fn) => fn());\r\n listener();\r\n return unsubscribe;\r\n}","import { useState } from \"react\";\r\n\r\nimport type { InitialState, Notifier } from \"../types\";\r\nimport { notifier as createNotifier } from \"../utils/notifier\";\r\n\r\n/**\r\n * Creates a component-scoped, lazy-initialized notifier with automatic \r\n * proxy-driven nested reactivity.\r\n * \r\n * @remarks\r\n * Tied directly to the component lifecycle. Every property on the initial state \r\n * object automatically becomes a first-class sub-notifier.\r\n * \r\n * @see [Barrex Docs](./docs/hooks/use-notifier.md)\r\n * \r\n * @template T The shape of the initial state.\r\n * @param initialState The initial value or a lazy initializer function returning the state.\r\n * @returns A root Notifier proxy instance.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useNotifier, useListener } from \"barrex\";\r\n * \r\n * function Profile() {\r\n * const userNotifier = useNotifier({ name: \"Alice\", age: 40 });\r\n * const name = useListener(userNotifier.name);\r\n * return <p>{name}</p>;\r\n * }\r\n * ```\r\n */\r\nexport function useNotifier<T>(initialState: InitialState<T>): Notifier<T> {\r\n const [notifier] = useState(() => createNotifier(initialState));\r\n return notifier;\r\n}","import { useRef, useSyncExternalStore } from \"react\";\r\n\r\nimport type { Notifier, StatesComparer, StateSelector } from \"../types\";\r\n\r\n/**\r\n * Subscribes a React component to a `barrex` notifier, enabling precise, \r\n * fine-grained reactivity using `useSyncExternalStore`.\r\n * \r\n * @remarks\r\n * Components re-render only when the exact state slice or computed selector \r\n * value updates, preventing unnecessary re-renders across the tree.\r\n * \r\n * @see [Barrex Docs](./docs/hooks/use-listener.md)\r\n * \r\n * @template T The raw type of the source notifier state.\r\n * @template U The resolved type after applying the selector.\r\n * \r\n * @param notifier The source notifier instance to subscribe to.\r\n * @param selector Optional function to transform or compute a specific slice from the notifier state.\r\n * @param areStatesEqual Optional custom comparer. Returns true to reuse the previous state reference and skip re-renders.\r\n * @returns The current resolved state (raw or selected).\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useListener } from \"barrex\";\r\n * \r\n * function Counter() {\r\n * const count = useListener(counterNotifier);\r\n * return <span>Count: {count}</span>;\r\n * }\r\n * ```\r\n */\r\nexport function useListener<T, U = T>(\r\n notifier: Notifier<T>,\r\n selector?: StateSelector<T, U>,\r\n areStatesEqual?: StatesComparer<U>\r\n): U {\r\n const prevState = useRef<U>(null);\r\n\r\n return useSyncExternalStore(\r\n notifier.subscribe,\r\n () => {\r\n const nextState = selector\r\n ? selector(notifier.get())\r\n : notifier.get() as unknown as U;\r\n if (areStatesEqual && prevState.current !== null) {\r\n const areEqual = areStatesEqual(prevState.current, nextState);\r\n if (areEqual) return prevState.current;\r\n }\r\n prevState.current = nextState;\r\n return nextState;\r\n },\r\n () => (selector ? selector(notifier.get()) : notifier.get() as unknown as U)\r\n );\r\n}","import { useCallback, useRef, useSyncExternalStore } from \"react\";\r\n\r\nimport type {\r\n InferNotifierValues,\r\n Notifier,\r\n StatesComparer,\r\n StateSelector,\r\n VoidCallback\r\n} from \"../types\";\r\nimport { isArray } from \"../utils/helpers\";\r\n\r\nfunction areStatesEqualFn<T>(prevState: T, nextState: T) {\r\n if (\r\n isArray(prevState) &&\r\n isArray(nextState) &&\r\n prevState.length === nextState.length\r\n ) {\r\n return prevState.every((prevValue, index) => {\r\n const nextValue = nextState[index];\r\n return prevValue === nextValue;\r\n });\r\n }\r\n return prevState === nextState;\r\n};\r\n\r\n/**\r\n * Subscribes a React component to multiple notifiers simultaneously, \r\n * offering complete type safety and optimized derivations.\r\n * \r\n * @remarks\r\n * Bundles multiple notifier subscriptions into a single unified cleanup routine \r\n * and includes smart array/tuple shallow comparison by default.\r\n * \r\n * @see [Barrex Docs](./docs/hooks/use-multi-listener.md)\r\n * \r\n * @param notifiers A readonly tuple array of source notifiers to subscribe to.\r\n * @param selector Optional function to transform or combine the tuple values into a custom shape.\r\n * @param areStatesEqual Optional custom comparator. Defaults to a smart tuple-aware shallow equality checker.\r\n * @returns The resolved state tuple or the computed selector output.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useMultiListener } from \"barrex\";\r\n * \r\n * function Header() {\r\n * const [name, theme] = useMultiListener([userNotifier.name, themeNotifier]);\r\n * return <header className={theme}>Welcome, {name}</header>;\r\n * }\r\n * ```\r\n */\r\nexport function useMultiListener<\r\n const T extends readonly Notifier<unknown>[],\r\n const U\r\n>(\r\n notifiers: T,\r\n selector: StateSelector<InferNotifierValues<T>, U>,\r\n areStatesEqual?: StatesComparer<U>\r\n): U;\r\n\r\nexport function useMultiListener<\r\n const T extends readonly Notifier<unknown>[]\r\n>(\r\n notifiers: T,\r\n selector?: undefined,\r\n areStatesEqual?: StatesComparer<InferNotifierValues<T>>\r\n): InferNotifierValues<T>;\r\n\r\nexport function useMultiListener(\r\n notifiers: Notifier<unknown>[],\r\n selector?: StateSelector<any, any>,\r\n areStatesEqual: StatesComparer<any> = areStatesEqualFn\r\n): unknown {\r\n const prevState = useRef<unknown>(null);\r\n\r\n const subscribe = useCallback((callback: VoidCallback) => {\r\n const unsubscribeFns = notifiers.map((notifier) => {\r\n return notifier.subscribe(callback);\r\n });\r\n return () => unsubscribeFns.forEach((fn) => fn());\r\n }, notifiers);\r\n\r\n const getSnapshot = () => {\r\n const state = notifiers.map((notifier) => notifier.get());\r\n const nextState = selector ? selector(state) : state;\r\n if (prevState.current !== null) {\r\n const areEqual = areStatesEqual(prevState.current, nextState);\r\n if (areEqual) return prevState.current;\r\n }\r\n prevState.current = nextState;\r\n return nextState;\r\n };\r\n\r\n return useSyncExternalStore(\r\n subscribe,\r\n getSnapshot,\r\n getSnapshot\r\n );\r\n}","import { memo } from \"react\";\r\n\r\nimport type { ListenerProps } from \"../types\";\r\nimport { useListener } from \"../hooks/useListener\";\r\n\r\nfunction ListenerComponent<T, U = T>({\r\n notifier,\r\n selector,\r\n areStatesEqual,\r\n stableChild,\r\n children\r\n}: ListenerProps<T, U>) {\r\n const state = useListener(notifier, selector, areStatesEqual);\r\n return children(state, stableChild);\r\n}\r\n\r\n/**\r\n * A declarative component wrapper that brings fine-grained reactivity \r\n * and granular performance optimization directly into your JSX tree.\r\n * \r\n * @remarks\r\n * Confines updates strictly to its render-prop children without forcing \r\n * an entire component function to re-render.\r\n * \r\n * @see [Barrex Docs](./docs/components/listener.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { Listener } from \"barrex\";\r\n * \r\n * <Listener notifier={userNotifier.name}>\r\n * {(name) => <h1>Welcome, {name}!</h1>}\r\n * </Listener>\r\n * ```\r\n */\r\nexport const Listener = memo(\r\n ListenerComponent,\r\n (prevProps, nextProps) => {\r\n if (nextProps.isolated) return true;\r\n return (\r\n prevProps.notifier === nextProps.notifier &&\r\n prevProps.selector === nextProps.selector &&\r\n prevProps.areStatesEqual === nextProps.areStatesEqual &&\r\n prevProps.stableChild === nextProps.stableChild &&\r\n prevProps.children === nextProps.children\r\n );\r\n }\r\n) as typeof ListenerComponent;","import { memo } from \"react\";\r\n\r\nimport { useMultiListener } from \"../hooks/useMultiListener\";\r\nimport type { MultiListenerComponent as MultiListenerComponentType } from \"../types\";\r\n\r\nfunction MultiListenerComponent({\r\n notifiers,\r\n selector,\r\n areStatesEqual,\r\n stableChild,\r\n children\r\n}: any) {\r\n const state = useMultiListener(notifiers, selector, areStatesEqual);\r\n return children(state, stableChild);\r\n}\r\n\r\n/**\r\n * An advanced declarative component wrapper that enables fine-grained \r\n * subscriptions to multiple notifiers simultaneously with full type safety.\r\n * \r\n * @remarks\r\n * Automatically infers tuple types from the provided notifiers array \r\n * and includes smart array equality checking.\r\n * \r\n * @see [Barrex Docs](./docs/components/multi-listener.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { MultiListener } from \"barrex\";\r\n * \r\n * <MultiListener notifiers={[userNotifier.name, cartNotifier.count]}>\r\n * {([name, count]) => <p>{name} has {count} items</p>}\r\n * </MultiListener>\r\n * ```\r\n */\r\nexport const MultiListener: MultiListenerComponentType = memo(\r\n MultiListenerComponent,\r\n (prevProps, nextProps) => {\r\n if (nextProps.isolated) return true;\r\n return (\r\n prevProps.notifiers === nextProps.notifiers &&\r\n prevProps.selector === nextProps.selector &&\r\n prevProps.areStatesEqual === nextProps.areStatesEqual &&\r\n prevProps.stableChild === nextProps.stableChild &&\r\n prevProps.children === nextProps.children\r\n );\r\n }\r\n);","import { memo } from \"react\";\r\n\r\nimport type { IsolatedContainerProps } from \"../types\";\r\n\r\nfunction IsolatedContainerComponent({ children }: IsolatedContainerProps) {\r\n return <>{children}</>;\r\n}\r\n\r\n/**\r\n * A boundary component designed to completely shield its child \r\n * subtree from parent-driven re-render cascades.\r\n * \r\n * @remarks\r\n * Children inside an `IsolatedContainer` can still re-render independently \r\n * based on their own local state or external reactive bindings (like `barrex` notifiers).\r\n * \r\n * @see [Barrex Docs](./docs/components/isolated-container.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { IsolatedContainer } from \"barrex\";\r\n * \r\n * <IsolatedContainer>\r\n * <StaticHeader/>\r\n * <CounterWidget/>\r\n * </IsolatedContainer>\r\n * ```\r\n */\r\nexport const IsolatedContainer = memo(\r\n IsolatedContainerComponent,\r\n () => true\r\n) as typeof IsolatedContainerComponent;"]}
1
+ {"version":3,"sources":["../src/utils/helpers.ts","../src/notifier.ts","../src/utils/notifier.ts","../src/utils/listener.ts","../src/utils/multi-listener.ts","../src/hooks/useNotifier.ts","../src/hooks/useListener.ts","../src/hooks/useMultiListener.ts","../src/components/Listener.tsx","../src/components/MultiListener.tsx","../src/components/IsolatedContainer.tsx"],"names":["isObjectOrArray","value","isArray","isFunction","NotifierRoot","state","RootNode","Node","callback","listener","child","prevState","newState","key","index","prevChildState","_","prop","childNode","ChildNode","root","fromChild","parent","parentState","newParentState","functionCannotBeNotifierMessage","notifier","initialState","createNotifier","unsubscribe","multiListener","notifiers","unsubscribeFns","fn","useNotifier","useState","useListener","selector","areStatesEqual","useRef","useSyncExternalStore","nextState","areStatesEqualFn","prevValue","nextValue","useMultiListener","subscribe","useCallback","getSnapshot","ListenerComponent","stableChild","children","Listener","memo","prevProps","nextProps","MultiListenerComponent","MultiListener","IsolatedContainerComponent","jsx","Fragment","IsolatedContainer"],"mappings":"uHAAO,SAASA,CAAAA,CAAgBC,CAAAA,CAAiC,CAC7D,OAAO,OAAOA,GAAU,QAAA,EAAYA,CAAAA,GAAU,IAClD,CAEO,SAASC,CAAAA,CAAQD,EAAyC,CAC7D,OAAO,KAAA,CAAM,OAAA,CAAQA,CAAK,CAC9B,CAEO,SAASE,CAAAA,CAAWF,CAAAA,CAAmC,CAC1D,OAAO,OAAOA,GAAU,UAC5B,CCFO,IAAMG,CAAAA,CAAN,KAAmB,CACf,MACA,QAAA,CAEP,WAAA,CAAYC,CAAAA,CAAgB,CACxB,IAAA,CAAK,KAAA,CAAQA,EACb,IAAA,CAAK,QAAA,CAAW,IAAIC,CAAAA,CAAS,IAAI,EACrC,CACJ,CAAA,CAEeC,CAAAA,CAAf,KAAoB,CACN,WAAA,CACF,SAAA,CACA,SACD,KAAA,CAEP,WAAA,EAAc,CACV,IAAA,CAAK,WAAA,CAAc,IAAA,CACnB,KAAK,SAAA,CAAY,IAAI,GAAA,CACrB,IAAA,CAAK,QAAA,CAAW,IAAI,IACpB,IAAA,CAAK,KAAA,CAAQ,IAAA,CAAK,WAAA,GACtB,CAKO,YAAeF,CAAAA,EACX,IAAA,CAAK,GAAA,CAAIA,CAAAA,CAAO,KAAK,CAAA,CAGxB,UAAaG,CAAAA,GACjB,IAAA,CAAK,SAAA,CAAU,GAAA,CAAIA,CAAQ,CAAA,CACpB,IAAM,CACT,IAAA,CAAK,SAAA,CAAU,MAAA,CAAOA,CAAQ,EAClC,GAGM,eAAA,EAAkB,CACxB,IA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jCD,CAAAA,CAAU,iBAAmBC,CAAAA,CAAU,cAAA,EACvCD,CAAAA,CAAU,WAAA,GAAgBC,CAAAA,CAAU,WAAA,EACpCD,EAAU,QAAA,GAAaC,CAAAA,CAAU,QAG7C,EC7CA,SAASG,CAAAA,CAA2B,CAAE,QAAA,CAAAP,CAAS,CAAA,CAA2B,CACtE,OAAOQ,GAAAA,CAAAC,QAAAA,CAAA,CAAG,QAAA,CAAAT,CAAAA,CAAS,CACvB,CAwBO,IAAMU,CAAAA,CAAoBR,IAAAA,CAC7BK,CAAAA,CACA,IAAM,IACV","file":"index.js","sourcesContent":["export function isObjectOrArray(value: unknown): value is object {\r\n return typeof value === \"object\" && value !== null;\r\n}\r\n\r\nexport function isArray(value: unknown): value is Array<unknown> {\r\n return Array.isArray(value);\r\n}\r\n\r\nexport function isFunction(value: unknown): value is Function {\r\n return typeof value === \"function\";\r\n}","import type {\r\n NodeKey,\r\n SetState,\r\n StateUpdater,\r\n VoidCallback\r\n} from \"./types\";\r\nimport { isArray, isFunction, isObjectOrArray } from \"./utils/helpers\";\r\n\r\nexport class NotifierRoot {\r\n public state: unknown;\r\n public rootNode: RootNode;\r\n\r\n constructor(state: unknown) {\r\n this.state = state;\r\n this.rootNode = new RootNode(this);\r\n }\r\n}\r\n\r\nabstract class Node {\r\n protected cachedState: unknown;\r\n private listeners: Set<VoidCallback>;\r\n private children: Map<NodeKey, ChildNode>;\r\n public proxy: object;\r\n\r\n constructor() {\r\n this.cachedState = null;\r\n this.listeners = new Set();\r\n this.children = new Map();\r\n this.proxy = this.createProxy();\r\n }\r\n\r\n public abstract get(): unknown;\r\n public abstract set(state: SetState<unknown>, fromChild: boolean): boolean;\r\n\r\n public dispatchSet = (state: SetState<unknown>) => {\r\n return this.set(state, false);\r\n };\r\n\r\n private subscribe = (callback: VoidCallback) => {\r\n this.listeners.add(callback);\r\n return () => {\r\n this.listeners.delete(callback);\r\n };\r\n };\r\n\r\n protected notifyListeners() {\r\n this.listeners.forEach((listener) => listener());\r\n }\r\n\r\n private notifySubtree() {\r\n this.cachedState = null;\r\n this.notifyListeners();\r\n for (const child of this.children.values()) {\r\n child.notifySubtree();\r\n }\r\n }\r\n\r\n protected reconcileChildren(prevState: unknown, newState: unknown) {\r\n if (!isArray(prevState) || !isArray(newState)) {\r\n return;\r\n }\r\n for (const [key, child] of this.children) {\r\n const index = key as `${number}`;\r\n const prevChildState = prevState[index];\r\n const newChildState = newState[index];\r\n if (newChildState !== prevChildState) {\r\n child.notifySubtree();\r\n }\r\n }\r\n }\r\n\r\n private setTrap() { return false; }\r\n\r\n private createProxy() {\r\n return new Proxy(\r\n {},\r\n {\r\n get: (_, prop) => {\r\n if (prop === \"get\") return this.get;\r\n if (prop === \"set\") return this.dispatchSet;\r\n if (prop === \"subscribe\") return this.subscribe;\r\n\r\n const state = this.get();\r\n if (isObjectOrArray(state) && prop in state) {\r\n const value = (state as any)[prop];\r\n if (isFunction(value)) return value;\r\n\r\n let childNode = this.children.get(prop);\r\n if (!childNode) {\r\n childNode = new ChildNode(prop, this);\r\n this.children.set(prop, childNode);\r\n }\r\n return childNode.proxy;\r\n }\r\n },\r\n set: this.setTrap\r\n }\r\n );\r\n }\r\n}\r\n\r\nclass RootNode extends Node {\r\n private root: NotifierRoot;\r\n\r\n constructor(root: NotifierRoot) {\r\n super();\r\n this.root = root;\r\n }\r\n\r\n public get = () => this.root.state;\r\n\r\n public set(state: SetState<unknown>, fromChild: boolean) {\r\n const prevState = this.get();\r\n const newState = isFunction(state)\r\n ? (state as StateUpdater<unknown>)(prevState)\r\n : state;\r\n if (newState !== prevState) {\r\n this.root.state = newState;\r\n this.notifyListeners();\r\n if (!fromChild) {\r\n this.reconcileChildren(prevState, newState);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n}\r\n\r\nclass ChildNode extends Node {\r\n private key: NodeKey;\r\n private parent: Node;\r\n\r\n constructor(key: NodeKey, parent: Node) {\r\n super();\r\n this.key = key;\r\n this.parent = parent;\r\n }\r\n\r\n public get = (): unknown => {\r\n if (this.cachedState !== null) {\r\n return this.cachedState;\r\n }\r\n const state = (this.parent.get() as any)[this.key];\r\n this.cachedState = state;\r\n return state;\r\n }\r\n\r\n public set(state: SetState<unknown>, fromChild: boolean) {\r\n const parentState = this.parent.get();\r\n const prevState = (parentState as any)[this.key];\r\n const newState = isFunction(state)\r\n ? (state as StateUpdater<unknown>)(prevState)\r\n : state;\r\n if (newState !== prevState) {\r\n const newParentState = Object.assign(\r\n isArray(parentState) ? [] : {},\r\n parentState\r\n );\r\n (newParentState as any)[this.key] = newState;\r\n const isSet = this.parent.set(newParentState, true);\r\n if (isSet) {\r\n this.cachedState = newState;\r\n this.notifyListeners();\r\n if (!fromChild) {\r\n this.reconcileChildren(prevState, newState);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n return false;\r\n }\r\n}","import { isFunction } from \"./helpers\";\r\nimport { NotifierRoot } from \"../notifier\";\r\nimport type { InitialState, Notifier } from \"../types\";\r\n\r\nconst functionCannotBeNotifierMessage =\r\n \"A function cannot be a notifier. Replace it with other value, or add it as a property/method inside an object, or don't wrap it with notifier.\";\r\n\r\n/**\r\n * Creates a core, global root-level state container wrapped in a deeply reactive proxy tree.\r\n * \r\n * @remarks\r\n * Serves as the primary entry point for global stores outside of React. Every nested property \r\n * automatically becomes a sub-notifier. Raw functions cannot be notifiers and will throw an error.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/notifier.md)\r\n * \r\n * @template T The shape of the initial state.\r\n * @param initialState The initial value of the state, or a lazy initialization function returning the state.\r\n * @returns A root Notifier proxy instance.\r\n * \r\n * @example\r\n * ```ts\r\n * import { notifier } from \"barrex\";\r\n * \r\n * const authNotifier = notifier({\r\n * user: null,\r\n * isAuthenticated: false\r\n * });\r\n * ```\r\n */\r\nexport function notifier<T>(initialState: InitialState<T>): Notifier<T> {\r\n const state = (isFunction(initialState)\r\n ? (initialState as () => T)()\r\n : initialState) as T;\r\n if (isFunction(state)) {\r\n throw new Error(functionCannotBeNotifierMessage);\r\n }\r\n return createNotifier(state);\r\n}\r\n\r\nfunction createNotifier<T>(state: T): Notifier<T> {\r\n const root = new NotifierRoot(state);\r\n return root.rootNode.proxy as Notifier<T>;\r\n}","import type { ListenerCallback, Notifier, VoidCallback } from \"../types\";\r\n\r\n/**\r\n * Subscribes imperatively to a `barrex` notifier outside of React component trees.\r\n * \r\n * @remarks\r\n * Executes the callback immediately upon registration with the current state value, \r\n * and subsequently every time the notifier updates. Returns a cleanup function to unsubscribe.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/listener.md)\r\n * \r\n * @param notifier The source notifier instance to subscribe to.\r\n * @param callback A callback function invoked immediately and on every state update.\r\n * @returns A cleanup function to remove the subscription.\r\n * \r\n * @example\r\n * ```ts\r\n * import { listener } from \"barrex\";\r\n * \r\n * const unsubscribe = listener(themeNotifier, (theme) => {\r\n * localStorage.setItem(\"theme\", theme);\r\n * });\r\n * ```\r\n */\r\nexport function listener<T>(\r\n notifier: Notifier<T>,\r\n callback: ListenerCallback<T>\r\n): VoidCallback {\r\n const unsubscribe = notifier.subscribe(() => {\r\n callback(notifier.get());\r\n });\r\n callback(notifier.get());\r\n return unsubscribe;\r\n}","import type {\r\n InferNotifierValues,\r\n ListenerCallback,\r\n Notifier,\r\n VoidCallback\r\n} from \"../types\";\r\n\r\n/**\r\n * Subscribes imperatively to multiple `barrex` notifiers simultaneously outside of React.\r\n * \r\n * @remarks\r\n * Accepts a tuple array of notifiers, infers their types automatically, executes \r\n * the callback immediately with the initial values tuple, and returns a single composite cleanup function.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/utils/multi-listener.md)\r\n * \r\n * @param notifiers A readonly tuple array of source notifiers to subscribe to.\r\n * @param callback A callback function invoked immediately with the values tuple and on subsequent updates.\r\n * @returns A composite cleanup function to unsubscribe from all provided notifiers.\r\n * \r\n * @example\r\n * ```ts\r\n * import { multiListener } from \"barrex\";\r\n * \r\n * const unsubscribe = multiListener(\r\n * [userNotifier.name, settingsNotifier.theme],\r\n * ([name, theme]) => {\r\n * console.log(`User: ${name}, Theme: ${theme}`);\r\n * }\r\n * );\r\n * ```\r\n */\r\nexport function multiListener<\r\n const T extends readonly Notifier<unknown>[]\r\n>(\r\n notifiers: T,\r\n callback: ListenerCallback<InferNotifierValues<T>>\r\n): VoidCallback {\r\n const listener = () => {\r\n const state = notifiers.map((notifier) => notifier.get()) as any;\r\n callback(state);\r\n };\r\n const unsubscribeFns = notifiers.map((notifier) => {\r\n return notifier.subscribe(listener);\r\n });\r\n const unsubscribe = () => unsubscribeFns.forEach((fn) => fn());\r\n listener();\r\n return unsubscribe;\r\n}","import { useState } from \"react\";\r\n\r\nimport type { InitialState, Notifier } from \"../types\";\r\nimport { notifier as createNotifier } from \"../utils/notifier\";\r\n\r\n/**\r\n * Creates a component-scoped, lazy-initialized notifier with automatic \r\n * proxy-driven nested reactivity.\r\n * \r\n * @remarks\r\n * Tied directly to the component lifecycle. Every property on the initial state \r\n * object automatically becomes a first-class sub-notifier.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-notifier.md)\r\n * \r\n * @template T The shape of the initial state.\r\n * @param initialState The initial value or a lazy initializer function returning the state.\r\n * @returns A root Notifier proxy instance.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useNotifier, useListener } from \"barrex\";\r\n * \r\n * function Profile() {\r\n * const userNotifier = useNotifier({ name: \"Alice\", age: 40 });\r\n * const name = useListener(userNotifier.name);\r\n * return <p>{name}</p>;\r\n * }\r\n * ```\r\n */\r\nexport function useNotifier<T>(initialState: InitialState<T>): Notifier<T> {\r\n const [notifier] = useState(() => createNotifier(initialState));\r\n return notifier;\r\n}","import { useRef, useSyncExternalStore } from \"react\";\r\n\r\nimport type { Notifier, StatesComparer, StateSelector } from \"../types\";\r\n\r\n/**\r\n * Subscribes a React component to a `barrex` notifier, enabling precise, \r\n * fine-grained reactivity using `useSyncExternalStore`.\r\n * \r\n * @remarks\r\n * Components re-render only when the exact state slice or computed selector \r\n * value updates, preventing unnecessary re-renders across the tree.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-listener.md)\r\n * \r\n * @template T The raw type of the source notifier state.\r\n * @template U The resolved type after applying the selector.\r\n * \r\n * @param notifier The source notifier instance to subscribe to.\r\n * @param selector Optional function to transform or compute a specific slice from the notifier state.\r\n * @param areStatesEqual Optional custom comparer. Returns true to reuse the previous state reference and skip re-renders.\r\n * @returns The current resolved state (raw or selected).\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useListener } from \"barrex\";\r\n * \r\n * function Counter() {\r\n * const count = useListener(counterNotifier.count);\r\n * return <span>Count: {count}</span>;\r\n * }\r\n * ```\r\n */\r\nexport function useListener<T, U = T>(\r\n notifier: Notifier<T>,\r\n selector?: StateSelector<T, U>,\r\n areStatesEqual?: StatesComparer<U>\r\n): U {\r\n const prevState = useRef<U>(null);\r\n\r\n return useSyncExternalStore(\r\n notifier.subscribe,\r\n () => {\r\n const nextState = selector\r\n ? selector(notifier.get())\r\n : notifier.get() as unknown as U;\r\n if (areStatesEqual && prevState.current !== null) {\r\n const areEqual = areStatesEqual(prevState.current, nextState);\r\n if (areEqual) return prevState.current;\r\n }\r\n prevState.current = nextState;\r\n return nextState;\r\n },\r\n () => (selector ? selector(notifier.get()) : notifier.get() as unknown as U)\r\n );\r\n}","import { useCallback, useRef, useSyncExternalStore } from \"react\";\r\n\r\nimport type {\r\n InferNotifierValues,\r\n Notifier,\r\n StatesComparer,\r\n StateSelector,\r\n VoidCallback\r\n} from \"../types\";\r\nimport { isArray } from \"../utils/helpers\";\r\n\r\nfunction areStatesEqualFn<T>(prevState: T, nextState: T) {\r\n if (\r\n isArray(prevState) &&\r\n isArray(nextState) &&\r\n prevState.length === nextState.length\r\n ) {\r\n return prevState.every((prevValue, index) => {\r\n const nextValue = nextState[index];\r\n return prevValue === nextValue;\r\n });\r\n }\r\n return prevState === nextState;\r\n};\r\n\r\n/**\r\n * Subscribes a React component to multiple notifiers simultaneously, \r\n * offering complete type safety and optimized derivations.\r\n * \r\n * @remarks\r\n * Bundles multiple notifier subscriptions into a single unified cleanup routine \r\n * and includes smart array/tuple shallow comparison by default.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/hooks/use-multi-listener.md)\r\n * \r\n * @param notifiers A readonly tuple array of source notifiers to subscribe to.\r\n * @param selector Optional function to transform or combine the tuple values into a custom shape.\r\n * @param areStatesEqual Optional custom comparator. Defaults to a smart tuple-aware shallow equality checker.\r\n * @returns The resolved state tuple or the computed selector output.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { useMultiListener } from \"barrex\";\r\n * \r\n * function Header() {\r\n * const [name, theme] = useMultiListener([userNotifier.name, themeNotifier]);\r\n * return <header className={theme}>Welcome, {name}</header>;\r\n * }\r\n * ```\r\n */\r\nexport function useMultiListener<\r\n const T extends readonly Notifier<unknown>[],\r\n const U\r\n>(\r\n notifiers: T,\r\n selector: StateSelector<InferNotifierValues<T>, U>,\r\n areStatesEqual?: StatesComparer<U>\r\n): U;\r\n\r\nexport function useMultiListener<\r\n const T extends readonly Notifier<unknown>[]\r\n>(\r\n notifiers: T,\r\n selector?: undefined,\r\n areStatesEqual?: StatesComparer<InferNotifierValues<T>>\r\n): InferNotifierValues<T>;\r\n\r\nexport function useMultiListener(\r\n notifiers: Notifier<unknown>[],\r\n selector?: StateSelector<any, any>,\r\n areStatesEqual: StatesComparer<any> = areStatesEqualFn\r\n): unknown {\r\n const prevState = useRef<unknown>(null);\r\n\r\n const subscribe = useCallback((callback: VoidCallback) => {\r\n const unsubscribeFns = notifiers.map((notifier) => {\r\n return notifier.subscribe(callback);\r\n });\r\n return () => unsubscribeFns.forEach((fn) => fn());\r\n }, notifiers);\r\n\r\n const getSnapshot = () => {\r\n const state = notifiers.map((notifier) => notifier.get());\r\n const nextState = selector ? selector(state) : state;\r\n if (prevState.current !== null) {\r\n const areEqual = areStatesEqual(prevState.current, nextState);\r\n if (areEqual) return prevState.current;\r\n }\r\n prevState.current = nextState;\r\n return nextState;\r\n };\r\n\r\n return useSyncExternalStore(\r\n subscribe,\r\n getSnapshot,\r\n getSnapshot\r\n );\r\n}","import { memo } from \"react\";\r\n\r\nimport type { ListenerProps } from \"../types\";\r\nimport { useListener } from \"../hooks/useListener\";\r\n\r\nfunction ListenerComponent<T, U = T>({\r\n notifier,\r\n selector,\r\n areStatesEqual,\r\n stableChild,\r\n children\r\n}: ListenerProps<T, U>) {\r\n const state = useListener(notifier, selector, areStatesEqual);\r\n return children(state, stableChild);\r\n}\r\n\r\n/**\r\n * A declarative component wrapper that brings fine-grained reactivity \r\n * and granular performance optimization directly into your JSX tree.\r\n * \r\n * @remarks\r\n * Confines updates strictly to its render-prop children without forcing \r\n * an entire component function to re-render.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/listener.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { Listener } from \"barrex\";\r\n * \r\n * <Listener notifier={userNotifier.name}>\r\n * {(name) => <h1>Welcome, {name}!</h1>}\r\n * </Listener>\r\n * ```\r\n */\r\nexport const Listener = memo(\r\n ListenerComponent,\r\n (prevProps, nextProps) => {\r\n if (nextProps.isolated) return true;\r\n return (\r\n prevProps.notifier === nextProps.notifier &&\r\n prevProps.selector === nextProps.selector &&\r\n prevProps.areStatesEqual === nextProps.areStatesEqual &&\r\n prevProps.stableChild === nextProps.stableChild &&\r\n prevProps.children === nextProps.children\r\n );\r\n }\r\n) as typeof ListenerComponent;","import { memo } from \"react\";\r\n\r\nimport { useMultiListener } from \"../hooks/useMultiListener\";\r\nimport type { MultiListenerComponent as MultiListenerComponentType } from \"../types\";\r\n\r\nfunction MultiListenerComponent({\r\n notifiers,\r\n selector,\r\n areStatesEqual,\r\n stableChild,\r\n children\r\n}: any) {\r\n const state = useMultiListener(notifiers, selector, areStatesEqual);\r\n return children(state, stableChild);\r\n}\r\n\r\n/**\r\n * An advanced declarative component wrapper that enables fine-grained \r\n * subscriptions to multiple notifiers simultaneously with full type safety.\r\n * \r\n * @remarks\r\n * Automatically infers tuple types from the provided notifiers array \r\n * and includes smart array equality checking.\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/multi-listener.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { MultiListener } from \"barrex\";\r\n * \r\n * <MultiListener notifiers={[userNotifier.name, cartNotifier.count]}>\r\n * {([name, count]) => <p>{name} has {count} items</p>}\r\n * </MultiListener>\r\n * ```\r\n */\r\nexport const MultiListener: MultiListenerComponentType = memo(\r\n MultiListenerComponent,\r\n (prevProps, nextProps) => {\r\n if (nextProps.isolated) return true;\r\n return (\r\n prevProps.notifiers === nextProps.notifiers &&\r\n prevProps.selector === nextProps.selector &&\r\n prevProps.areStatesEqual === nextProps.areStatesEqual &&\r\n prevProps.stableChild === nextProps.stableChild &&\r\n prevProps.children === nextProps.children\r\n );\r\n }\r\n);","import { memo } from \"react\";\r\n\r\nimport type { IsolatedContainerProps } from \"../types\";\r\n\r\nfunction IsolatedContainerComponent({ children }: IsolatedContainerProps) {\r\n return <>{children}</>;\r\n}\r\n\r\n/**\r\n * A boundary component designed to completely shield its child \r\n * subtree from parent-driven re-render cascades.\r\n * \r\n * @remarks\r\n * Children inside an `IsolatedContainer` can still re-render independently \r\n * based on their own local state or external reactive bindings (like `barrex` notifiers).\r\n * \r\n * @see [Barrex Docs](https://github.com/bhuvanpddahal/barrex/blob/main/docs/components/isolated-container.md)\r\n * \r\n * @param props The component props.\r\n * \r\n * @example\r\n * ```tsx\r\n * import { IsolatedContainer } from \"barrex\";\r\n * \r\n * <IsolatedContainer>\r\n * <StaticHeader/>\r\n * <CounterWidget/>\r\n * </IsolatedContainer>\r\n * ```\r\n */\r\nexport const IsolatedContainer = memo(\r\n IsolatedContainerComponent,\r\n () => true\r\n) as typeof IsolatedContainerComponent;"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barrex",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "The bare essentials for state management in React.",
5
5
  "homepage": "https://github.com/bhuvanpddahal/barrex#readme",
6
6
  "repository": {