frosty 0.0.55 → 0.0.56

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/dist/index.d.ts CHANGED
@@ -488,7 +488,7 @@ declare const useRefHandle: <T, R extends T>(ref: Ref<T> | undefined, init: () =
488
488
  * }, [dependency]);
489
489
  */
490
490
  declare function useCallback<T extends (...args: any) => any>(callback: T, deps?: any): T;
491
- declare function useCallback<T extends (...args: any) => any>(callback: T | _.Falsey, deps?: any): T | _.Falsey;
491
+ declare function useCallback<T extends ((...args: any) => any) | _.Falsey>(callback: T, deps?: any): T;
492
492
 
493
493
  /**
494
494
  * A hook function for managing state within a custom framework or library.
@@ -1 +1 @@
1
- {"version":3,"file":"sync-BDjrdmZD.js","sources":["../../../src/core/reconciler/hooks.ts","../../../src/core/hooks/callback.ts","../../../src/core/hooks/effect.ts","../../../src/core/hooks/memo.ts","../../../src/core/hooks/sync.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { reconciler } from './state';\nimport { equalDeps } from './utils';\n\nconst _useHookState = (hook: string) => {\n const state = reconciler.currentHookState;\n if (!state) throw Error(`${hook} must be used within a render function.`);\n const { prevState, state: newState } = state;\n if (prevState && prevState[newState.length]?.hook !== hook) {\n console.warn([\n `Hook \"${hook}\" is called conditionally.`,\n 'Hooks must be called in the exact same order in every component render.',\n 'Did you accidentally call a hook after an early return?'\n ].join(' '));\n }\n return state;\n};\n\nexport const _useEffect = (\n hook: string,\n effect: (state: ReturnType<typeof _useHookState>) => () => void,\n deps?: any\n) => {\n const state = _useHookState(hook);\n const { state: newState } = state;\n newState.push({\n mount: () => effect(state),\n deps,\n hook,\n });\n};\n\nexport const _useMemo = <T>(\n hook: string,\n factory: (state: ReturnType<typeof _useHookState>) => T,\n deps?: any\n): T => {\n const state = _useHookState(hook);\n const { prevState, state: newState } = state;\n const idx = newState.length;\n const changed = prevState?.[idx]?.hook !== hook || !equalDeps(prevState[idx].deps, deps);\n const data = changed ? factory(state) : prevState[idx].data;\n newState.push({\n deps,\n hook,\n data\n });\n return data;\n};\n","//\n// memo.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { _useMemo } from '../reconciler/hooks';\n\n/**\n * A hook that memoizes a callback function, ensuring that it only changes\n * if its dependencies change. This is useful for optimizing performance by preventing\n * unnecessary re-creations of functions.\n *\n * @template T - The type of the callback function.\n * @param callback - The callback function to be memoized.\n * @param deps - An optional dependencies. If provided, the callback\n * will only be updated when one of these dependencies changes.\n * If not provided, the callback will remain stable.\n * @returns - A stable version of the callback function that will not change unless\n * its dependencies change.\n *\n * @example\n * const memoizedCallback = useCallback(() => {\n * console.log('This function is memoized!');\n * }, [dependency]);\n */\n\nexport function useCallback<T extends (...args: any) => any>(\n callback: T,\n deps?: any\n): T;\n\nexport function useCallback<T extends (...args: any) => any>(\n callback: T | _.Falsey,\n deps?: any\n): T | _.Falsey;\n\nexport function useCallback<T extends (...args: any) => any>(\n callback: T | _.Falsey,\n deps?: any\n): T | _.Falsey {\n if (!_.isUndefined(deps)) return _useMemo('useCallback', () => callback, deps);\n const store = _useMemo('useCallback', () => {\n const store = {\n current: callback,\n stable: (...args: Parameters<T>) => {\n if (store.current) return store.current(...args);\n },\n };\n return store;\n }, null);\n if (callback) store.current = callback;\n return callback && (store.stable as T);\n}\n","//\n// effect.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { Awaitable } from '@o2ter/utils-js';\nimport { _useEffect } from '../reconciler/hooks';\n\n/**\n * A hook that manages side effects with support for an `AbortSignal`.\n * It ensures proper cleanup logic and handles asynchronous operations effectively.\n *\n * @param effect - \n * A function that receives an `AbortSignal` and performs side effects. \n * It can optionally return a cleanup function or a promise that resolves to a cleanup function.\n *\n * @param deps - \n * An optional dependencies that determines when the effect should be re-executed.\n *\n * @example\n * useEffect((signal) => {\n * fetch('/api/data', { signal })\n * .then(response => response.json())\n * .then(data => console.log(data))\n * .catch(err => {\n * if (err.name === 'AbortError') {\n * console.log('Fetch aborted');\n * } else {\n * console.error(err);\n * }\n * });\n * \n * return () => {\n * console.log('Cleanup logic here');\n * };\n * }, []);\n */\nexport const useEffect = (\n effect: (\n signal: AbortSignal,\n ) => Awaitable<void | (() => Awaitable<void>)>,\n deps?: any,\n) => _useEffect('useEffect', () => {\n const abort = new AbortController();\n try {\n const destructor = effect(abort.signal);\n return () => {\n abort.abort();\n (async () => {\n try {\n const _destructor = await destructor;\n if (_.isFunction(_destructor)) _destructor();\n } catch (e) {\n console.error(e);\n }\n })();\n };\n } catch (e) {\n console.error(e);\n return () => abort.abort();\n }\n}, deps);","//\n// memo.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { _useMemo } from '../reconciler/hooks';\n\n/**\n * A utility function that memoizes the result of a factory function.\n * \n * @template T The type of the value returned by the factory function.\n * @param factory A function that produces a value to be memoized.\n * @param deps An optional dependency array. The memoized value is recalculated \n * only when the dependencies change.\n * @returns The memoized value produced by the factory function.\n */\nexport const useMemo = <T>(\n factory: () => T,\n deps?: any,\n) => _useMemo('useMemo', () => factory(), deps);\n","//\n// sync.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { Awaitable } from '@o2ter/utils-js';\nimport { _useEffect } from '../reconciler/hooks';\nimport { reconciler } from '../reconciler/state';\n\n/**\n * A hook utility for synchronizing with an external store.\n *\n * @template Snapshot - The type of the snapshot returned by the store.\n * @param subscribe - A function that sets up a subscription to the external store.\n * - `onStoreChange`: A callback to invoke when the store changes.\n * - `signal`: An `AbortSignal` to handle cleanup when the subscription is no longer needed.\n * - Returns an optional cleanup function or a promise resolving to one.\n * @param getSnapshot - A function that retrieves the current snapshot of the store.\n * @param getServerSnapshot - (Optional) A function that retrieves the snapshot of the store\n * in a server environment.\n * @returns The current snapshot of the store.\n *\n * @throws Will throw an error if used outside of a valid render context.\n */\nexport const useSyncExternalStore = <Snapshot>(\n subscribe: (\n onStoreChange: () => void,\n signal: AbortSignal,\n ) => Awaitable<void | (() => Awaitable<void>)>,\n getSnapshot: () => Snapshot,\n getServerSnapshot?: () => Snapshot,\n) => {\n const state = reconciler.currentHookState;\n if (!state) throw Error('useSyncExternalStore must be used within a render function.');\n _useEffect('useSyncExternalStore', ({ node }) => {\n const abort = new AbortController();\n try {\n const destructor = subscribe(() => { node?._setDirty(); }, abort.signal);\n return () => {\n abort.abort();\n (async () => {\n try {\n const _destructor = await destructor;\n if (_.isFunction(_destructor)) _destructor();\n } catch (e) {\n console.error(e);\n }\n })();\n };\n } catch (e) {\n console.error(e);\n return () => abort.abort();\n }\n }, null);\n if (getServerSnapshot && state.renderer._server) {\n return getServerSnapshot();\n }\n return getSnapshot();\n};"],"names":["state","reconciler","equalDeps"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMA,MAAM,aAAa,GAAG,CAAC,IAAY,KAAI;AACrC,IAAA,MAAMA,OAAK,GAAGC,gBAAU,CAAC,gBAAgB;AACzC,IAAA,IAAI,CAACD,OAAK;AAAE,QAAA,MAAM,KAAK,CAAC,CAAA,EAAG,IAAI,CAAA,uCAAA,CAAyC,CAAC;IACzE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAGA,OAAK;AAC5C,IAAA,IAAI,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,KAAK,IAAI,EAAE;QAC1D,OAAO,CAAC,IAAI,CAAC;AACX,YAAA,CAAA,MAAA,EAAS,IAAI,CAA4B,0BAAA,CAAA;YACzC,yEAAyE;YACzE;AACD,SAAA,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;;AAEd,IAAA,OAAOA,OAAK;AACd,CAAC;AAEY,MAAA,UAAU,GAAG,CACxB,IAAY,EACZ,MAA+D,EAC/D,IAAU,KACR;AACF,IAAA,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC;AACjC,IAAA,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK;IACjC,QAAQ,CAAC,IAAI,CAAC;AACZ,QAAA,KAAK,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI;QACJ,IAAI;AACL,KAAA,CAAC;AACJ;AAEa,MAAA,QAAQ,GAAG,CACtB,IAAY,EACZ,OAAuD,EACvD,IAAU,KACL;AACL,IAAA,MAAMA,OAA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;;;;;;;;;;;AAcG;AACU,MAAA,oBAAoB,GAAG,CAClC,SAG8C,EAC9C,WAA2B,EAC3B,iBAAkC,KAChC;AACF,IAAA,MAAMA,OAAK,GAAGC,gBAAU,CAAC,gBAAgB;AACzC,IAAA,IAAI,CAACD,OAAK;AAAE,QAAA,MAAM,KAAK,CAAC,6DAA6D,CAAC;IACtF,UAAU,CAAC,sBAAsB,EAAE,CAAC,EAAE,IAAI,EAAE,KAAI;AAC9C,QAAA,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE;AACnC,QAAA,IAAI;AACF,YAAA,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC;AACxE,YAAA,OAAO,MAAK;gBACV,KAAK,CAAC,KAAK,EAAE;gBACb,CAAC,YAAW;AACV,oBAAA,IAAI;AACF,wBAAA,MAAM,WAAW,GAAG,MAAM,UAAU;AACpC,wBAAA,IAAI,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC;AAAE,4BAAA,WAAW,EAAE;;oBAC5C,OAAO,CAAC,EAAE;AACV,wBAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;;iBAEnB,GAAG;AACN,aAAC;;QACD,OAAO,CAAC,EAAE;AACV,YAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAChB,YAAA,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE;;KAE7B,EAAE,IAAI,CAAC;IACR,IAAI,iBAAiB,IAAIA,OAAK,CAAC,QAAQ,CAAC,OAAO,EAAE;QAC/C,OAAO,iBAAiB,EAAE;;IAE5B,OAAO,WAAW,EAAE;AACtB;;;;;;;;;"}
1
+ {"version":3,"file":"sync-BDjrdmZD.js","sources":["../../../src/core/reconciler/hooks.ts","../../../src/core/hooks/callback.ts","../../../src/core/hooks/effect.ts","../../../src/core/hooks/memo.ts","../../../src/core/hooks/sync.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { reconciler } from './state';\nimport { equalDeps } from './utils';\n\nconst _useHookState = (hook: string) => {\n const state = reconciler.currentHookState;\n if (!state) throw Error(`${hook} must be used within a render function.`);\n const { prevState, state: newState } = state;\n if (prevState && prevState[newState.length]?.hook !== hook) {\n console.warn([\n `Hook \"${hook}\" is called conditionally.`,\n 'Hooks must be called in the exact same order in every component render.',\n 'Did you accidentally call a hook after an early return?'\n ].join(' '));\n }\n return state;\n};\n\nexport const _useEffect = (\n hook: string,\n effect: (state: ReturnType<typeof _useHookState>) => () => void,\n deps?: any\n) => {\n const state = _useHookState(hook);\n const { state: newState } = state;\n newState.push({\n mount: () => effect(state),\n deps,\n hook,\n });\n};\n\nexport const _useMemo = <T>(\n hook: string,\n factory: (state: ReturnType<typeof _useHookState>) => T,\n deps?: any\n): T => {\n const state = _useHookState(hook);\n const { prevState, state: newState } = state;\n const idx = newState.length;\n const changed = prevState?.[idx]?.hook !== hook || !equalDeps(prevState[idx].deps, deps);\n const data = changed ? factory(state) : prevState[idx].data;\n newState.push({\n deps,\n hook,\n data\n });\n return data;\n};\n","//\n// memo.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { _useMemo } from '../reconciler/hooks';\n\n/**\n * A hook that memoizes a callback function, ensuring that it only changes\n * if its dependencies change. This is useful for optimizing performance by preventing\n * unnecessary re-creations of functions.\n *\n * @template T - The type of the callback function.\n * @param callback - The callback function to be memoized.\n * @param deps - An optional dependencies. If provided, the callback\n * will only be updated when one of these dependencies changes.\n * If not provided, the callback will remain stable.\n * @returns - A stable version of the callback function that will not change unless\n * its dependencies change.\n *\n * @example\n * const memoizedCallback = useCallback(() => {\n * console.log('This function is memoized!');\n * }, [dependency]);\n */\n\nexport function useCallback<T extends (...args: any) => any>(\n callback: T,\n deps?: any\n): T;\n\nexport function useCallback<T extends ((...args: any) => any) | _.Falsey>(\n callback: T,\n deps?: any\n): T;\n\nexport function useCallback<T extends ((...args: any) => any) | _.Falsey>(\n callback: T,\n deps?: any\n): T {\n if (!_.isUndefined(deps)) return _useMemo('useCallback', () => callback, deps);\n const store = _useMemo('useCallback', () => {\n const store = {\n current: callback,\n stable: (...args: any) => {\n if (store.current) return store.current(...args);\n },\n };\n return store;\n }, null);\n if (callback) store.current = callback;\n return callback && (store.stable as T);\n}\n","//\n// effect.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { Awaitable } from '@o2ter/utils-js';\nimport { _useEffect } from '../reconciler/hooks';\n\n/**\n * A hook that manages side effects with support for an `AbortSignal`.\n * It ensures proper cleanup logic and handles asynchronous operations effectively.\n *\n * @param effect - \n * A function that receives an `AbortSignal` and performs side effects. \n * It can optionally return a cleanup function or a promise that resolves to a cleanup function.\n *\n * @param deps - \n * An optional dependencies that determines when the effect should be re-executed.\n *\n * @example\n * useEffect((signal) => {\n * fetch('/api/data', { signal })\n * .then(response => response.json())\n * .then(data => console.log(data))\n * .catch(err => {\n * if (err.name === 'AbortError') {\n * console.log('Fetch aborted');\n * } else {\n * console.error(err);\n * }\n * });\n * \n * return () => {\n * console.log('Cleanup logic here');\n * };\n * }, []);\n */\nexport const useEffect = (\n effect: (\n signal: AbortSignal,\n ) => Awaitable<void | (() => Awaitable<void>)>,\n deps?: any,\n) => _useEffect('useEffect', () => {\n const abort = new AbortController();\n try {\n const destructor = effect(abort.signal);\n return () => {\n abort.abort();\n (async () => {\n try {\n const _destructor = await destructor;\n if (_.isFunction(_destructor)) _destructor();\n } catch (e) {\n console.error(e);\n }\n })();\n };\n } catch (e) {\n console.error(e);\n return () => abort.abort();\n }\n}, deps);","//\n// memo.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { _useMemo } from '../reconciler/hooks';\n\n/**\n * A utility function that memoizes the result of a factory function.\n * \n * @template T The type of the value returned by the factory function.\n * @param factory A function that produces a value to be memoized.\n * @param deps An optional dependency array. The memoized value is recalculated \n * only when the dependencies change.\n * @returns The memoized value produced by the factory function.\n */\nexport const useMemo = <T>(\n factory: () => T,\n deps?: any,\n) => _useMemo('useMemo', () => factory(), deps);\n","//\n// sync.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { Awaitable } from '@o2ter/utils-js';\nimport { _useEffect } from '../reconciler/hooks';\nimport { reconciler } from '../reconciler/state';\n\n/**\n * A hook utility for synchronizing with an external store.\n *\n * @template Snapshot - The type of the snapshot returned by the store.\n * @param subscribe - A function that sets up a subscription to the external store.\n * - `onStoreChange`: A callback to invoke when the store changes.\n * - `signal`: An `AbortSignal` to handle cleanup when the subscription is no longer needed.\n * - Returns an optional cleanup function or a promise resolving to one.\n * @param getSnapshot - A function that retrieves the current snapshot of the store.\n * @param getServerSnapshot - (Optional) A function that retrieves the snapshot of the store\n * in a server environment.\n * @returns The current snapshot of the store.\n *\n * @throws Will throw an error if used outside of a valid render context.\n */\nexport const useSyncExternalStore = <Snapshot>(\n subscribe: (\n onStoreChange: () => void,\n signal: AbortSignal,\n ) => Awaitable<void | (() => Awaitable<void>)>,\n getSnapshot: () => Snapshot,\n getServerSnapshot?: () => Snapshot,\n) => {\n const state = reconciler.currentHookState;\n if (!state) throw Error('useSyncExternalStore must be used within a render function.');\n _useEffect('useSyncExternalStore', ({ node }) => {\n const abort = new AbortController();\n try {\n const destructor = subscribe(() => { node?._setDirty(); }, abort.signal);\n return () => {\n abort.abort();\n (async () => {\n try {\n const _destructor = await destructor;\n if (_.isFunction(_destructor)) _destructor();\n } catch (e) {\n console.error(e);\n }\n })();\n };\n } catch (e) {\n console.error(e);\n return () => abort.abort();\n }\n }, null);\n if (getServerSnapshot && state.renderer._server) {\n return getServerSnapshot();\n }\n return getSnapshot();\n};"],"names":["state","reconciler","equalDeps"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMA,MAAM,aAAa,GAAG,CAAC,IAAY,KAAI;AACrC,IAAA,MAAMA,OAAK,GAAGC,gBAAU,CAAC,gBAAgB;AACzC,IAAA,IAAI,CAACD,OAAK;AAAE,QAAA,MAAM,KAAK,CAAC,CAAA,EAAG,IAAI,CAAA,uCAAA,CAAyC,CAAC;IACzE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAGA,OAAK;AAC5C,IAAA,IAAI,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,KAAK,IAAI,E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CAAC,WAAW,CAAC;AAAE,4BAAA,WAAW,EAAE;;oBAC5C,OAAO,CAAC,EAAE;AACV,wBAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;;iBAEnB,GAAG;AACN,aAAC;;QACD,OAAO,CAAC,EAAE;AACV,YAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAChB,YAAA,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE;;KAE7B,EAAE,IAAI,CAAC;IACR,IAAI,iBAAiB,IAAIA,OAAK,CAAC,QAAQ,CAAC,OAAO,EAAE;QAC/C,OAAO,iBAAiB,EAAE;;IAE5B,OAAO,WAAW,EAAE;AACtB;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"sync-BGejUV_c.mjs","sources":["../../../src/core/reconciler/hooks.ts","../../../src/core/hooks/callback.ts","../../../src/core/hooks/effect.ts","../../../src/core/hooks/memo.ts","../../../src/core/hooks/sync.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { reconciler } from './state';\nimport { equalDeps } from './utils';\n\nconst _useHookState = (hook: string) => {\n const state = reconciler.currentHookState;\n if (!state) throw Error(`${hook} must be used within a render function.`);\n const { prevState, state: newState } = state;\n if (prevState && prevState[newState.length]?.hook !== hook) {\n console.warn([\n `Hook \"${hook}\" is called conditionally.`,\n 'Hooks must be called in the exact same order in every component render.',\n 'Did you accidentally call a hook after an early return?'\n ].join(' '));\n }\n return state;\n};\n\nexport const _useEffect = (\n hook: string,\n effect: (state: ReturnType<typeof _useHookState>) => () => void,\n deps?: any\n) => {\n const state = _useHookState(hook);\n const { state: newState } = state;\n newState.push({\n mount: () => effect(state),\n deps,\n hook,\n });\n};\n\nexport const _useMemo = <T>(\n hook: string,\n factory: (state: ReturnType<typeof _useHookState>) => T,\n deps?: any\n): T => {\n const state = _useHookState(hook);\n const { prevState, state: newState } = state;\n const idx = newState.length;\n const changed = prevState?.[idx]?.hook !== hook || !equalDeps(prevState[idx].deps, deps);\n const data = changed ? factory(state) : prevState[idx].data;\n newState.push({\n deps,\n hook,\n data\n });\n return data;\n};\n","//\n// memo.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { _useMemo } from '../reconciler/hooks';\n\n/**\n * A hook that memoizes a callback function, ensuring that it only changes\n * if its dependencies change. This is useful for optimizing performance by preventing\n * unnecessary re-creations of functions.\n *\n * @template T - The type of the callback function.\n * @param callback - The callback function to be memoized.\n * @param deps - An optional dependencies. If provided, the callback\n * will only be updated when one of these dependencies changes.\n * If not provided, the callback will remain stable.\n * @returns - A stable version of the callback function that will not change unless\n * its dependencies change.\n *\n * @example\n * const memoizedCallback = useCallback(() => {\n * console.log('This function is memoized!');\n * }, [dependency]);\n */\n\nexport function useCallback<T extends (...args: any) => any>(\n callback: T,\n deps?: any\n): T;\n\nexport function useCallback<T extends (...args: any) => any>(\n callback: T | _.Falsey,\n deps?: any\n): T | _.Falsey;\n\nexport function useCallback<T extends (...args: any) => any>(\n callback: T | _.Falsey,\n deps?: any\n): T | _.Falsey {\n if (!_.isUndefined(deps)) return _useMemo('useCallback', () => callback, deps);\n const store = _useMemo('useCallback', () => {\n const store = {\n current: callback,\n stable: (...args: Parameters<T>) => {\n if (store.current) return store.current(...args);\n },\n };\n return store;\n }, null);\n if (callback) store.current = callback;\n return callback && (store.stable as T);\n}\n","//\n// effect.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { Awaitable } from '@o2ter/utils-js';\nimport { _useEffect } from '../reconciler/hooks';\n\n/**\n * A hook that manages side effects with support for an `AbortSignal`.\n * It ensures proper cleanup logic and handles asynchronous operations effectively.\n *\n * @param effect - \n * A function that receives an `AbortSignal` and performs side effects. \n * It can optionally return a cleanup function or a promise that resolves to a cleanup function.\n *\n * @param deps - \n * An optional dependencies that determines when the effect should be re-executed.\n *\n * @example\n * useEffect((signal) => {\n * fetch('/api/data', { signal })\n * .then(response => response.json())\n * .then(data => console.log(data))\n * .catch(err => {\n * if (err.name === 'AbortError') {\n * console.log('Fetch aborted');\n * } else {\n * console.error(err);\n * }\n * });\n * \n * return () => {\n * console.log('Cleanup logic here');\n * };\n * }, []);\n */\nexport const useEffect = (\n effect: (\n signal: AbortSignal,\n ) => Awaitable<void | (() => Awaitable<void>)>,\n deps?: any,\n) => _useEffect('useEffect', () => {\n const abort = new AbortController();\n try {\n const destructor = effect(abort.signal);\n return () => {\n abort.abort();\n (async () => {\n try {\n const _destructor = await destructor;\n if (_.isFunction(_destructor)) _destructor();\n } catch (e) {\n console.error(e);\n }\n })();\n };\n } catch (e) {\n console.error(e);\n return () => abort.abort();\n }\n}, deps);","//\n// memo.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { _useMemo } from '../reconciler/hooks';\n\n/**\n * A utility function that memoizes the result of a factory function.\n * \n * @template T The type of the value returned by the factory function.\n * @param factory A function that produces a value to be memoized.\n * @param deps An optional dependency array. The memoized value is recalculated \n * only when the dependencies change.\n * @returns The memoized value produced by the factory function.\n */\nexport const useMemo = <T>(\n factory: () => T,\n deps?: any,\n) => _useMemo('useMemo', () => factory(), deps);\n","//\n// sync.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { Awaitable } from '@o2ter/utils-js';\nimport { _useEffect } from '../reconciler/hooks';\nimport { reconciler } from '../reconciler/state';\n\n/**\n * A hook utility for synchronizing with an external store.\n *\n * @template Snapshot - The type of the snapshot returned by the store.\n * @param subscribe - A function that sets up a subscription to the external store.\n * - `onStoreChange`: A callback to invoke when the store changes.\n * - `signal`: An `AbortSignal` to handle cleanup when the subscription is no longer needed.\n * - Returns an optional cleanup function or a promise resolving to one.\n * @param getSnapshot - A function that retrieves the current snapshot of the store.\n * @param getServerSnapshot - (Optional) A function that retrieves the snapshot of the store\n * in a server environment.\n * @returns The current snapshot of the store.\n *\n * @throws Will throw an error if used outside of a valid render context.\n */\nexport const useSyncExternalStore = <Snapshot>(\n subscribe: (\n onStoreChange: () => void,\n signal: AbortSignal,\n ) => Awaitable<void | (() => Awaitable<void>)>,\n getSnapshot: () => Snapshot,\n getServerSnapshot?: () => Snapshot,\n) => {\n const state = reconciler.currentHookState;\n if (!state) throw Error('useSyncExternalStore must be used within a render function.');\n _useEffect('useSyncExternalStore', ({ node }) => {\n const abort = new AbortController();\n try {\n const destructor = subscribe(() => { node?._setDirty(); }, abort.signal);\n return () => {\n abort.abort();\n (async () => {\n try {\n const _destructor = await destructor;\n if (_.isFunction(_destructor)) _destructor();\n } catch (e) {\n console.error(e);\n }\n })();\n };\n } catch (e) {\n console.error(e);\n return () => abort.abort();\n }\n }, null);\n if (getServerSnapshot && state.renderer._server) {\n return getServerSnapshot();\n }\n return getSnapshot();\n};"],"names":[],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMA,MAAM,aAAa,GAAG,CAAC,IAAY,KAAI;AACrC,IAAA,MAAM,KAAK,GAAG,UAAU,CAAC,gBAAgB;AACzC,IAAA,IAAI,CAAC,KAAK;AAAE,QAAA,MAAM,KAAK,CAAC,CAAA,EAAG,IAAI,CAAA,uCAAA,CAAyC,CAAC;IACzE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK;AAC5C,IAAA,IAAI,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,KAAK,IAAI,EAAE;QAC1D,OAAO,CAAC,IAAI,CAAC;AACX,YAAA,CAAA,MAAA,EAAS,IAAI,CAA4B,0BAAA,CAAA;YACzC,yEAAyE;YACzE;AACD,SAAA,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;;AAEd,IAAA,OAAO,KAAK;AACd,CAAC;AAEY,MAAA,UAAU,GAAG,CACxB,IAAY,EACZ,MAA+D,EAC/D,IAAU,KACR;AACF,IAAA,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC;AACjC,IAAA,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK;IACjC,QAAQ,CAAC,IAAI,CAAC;AACZ,QAAA,KAAK,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI;QACJ,IAAI;AACL,KAAA,CAAC;AACJ;AAEa,MAAA,QAAQ,GAAG,CACtB,IAAY,EACZ,OAAuD,EACvD,IAAU,KACL;AACL,IAAA,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,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A,oBAAoB,GAAG,CAClC,SAG8C,EAC9C,WAA2B,EAC3B,iBAAkC,KAChC;AACF,IAAA,MAAM,KAAK,GAAG,UAAU,CAAC,gBAAgB;AACzC,IAAA,IAAI,CAAC,KAAK;AAAE,QAAA,MAAM,KAAK,CAAC,6DAA6D,CAAC;IACtF,UAAU,CAAC,sBAAsB,EAAE,CAAC,EAAE,IAAI,EAAE,KAAI;AAC9C,QAAA,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE;AACnC,QAAA,IAAI;AACF,YAAA,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC;AACxE,YAAA,OAAO,MAAK;gBACV,KAAK,CAAC,KAAK,EAAE;gBACb,CAAC,YAAW;AACV,oBAAA,IAAI;AACF,wBAAA,MAAM,WAAW,GAAG,MAAM,UAAU;AACpC,wBAAA,IAAI,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC;AAAE,4BAAA,WAAW,EAAE;;oBAC5C,OAAO,CAAC,EAAE;AACV,wBAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;;iBAEnB,GAAG;AACN,aAAC;;QACD,OAAO,CAAC,EAAE;AACV,YAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAChB,YAAA,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE;;KAE7B,EAAE,IAAI,CAAC;IACR,IAAI,iBAAiB,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE;QAC/C,OAAO,iBAAiB,EAAE;;IAE5B,OAAO,WAAW,EAAE;AACtB;;;;"}
1
+ {"version":3,"file":"sync-BGejUV_c.mjs","sources":["../../../src/core/reconciler/hooks.ts","../../../src/core/hooks/callback.ts","../../../src/core/hooks/effect.ts","../../../src/core/hooks/memo.ts","../../../src/core/hooks/sync.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { reconciler } from './state';\nimport { equalDeps } from './utils';\n\nconst _useHookState = (hook: string) => {\n const state = reconciler.currentHookState;\n if (!state) throw Error(`${hook} must be used within a render function.`);\n const { prevState, state: newState } = state;\n if (prevState && prevState[newState.length]?.hook !== hook) {\n console.warn([\n `Hook \"${hook}\" is called conditionally.`,\n 'Hooks must be called in the exact same order in every component render.',\n 'Did you accidentally call a hook after an early return?'\n ].join(' '));\n }\n return state;\n};\n\nexport const _useEffect = (\n hook: string,\n effect: (state: ReturnType<typeof _useHookState>) => () => void,\n deps?: any\n) => {\n const state = _useHookState(hook);\n const { state: newState } = state;\n newState.push({\n mount: () => effect(state),\n deps,\n hook,\n });\n};\n\nexport const _useMemo = <T>(\n hook: string,\n factory: (state: ReturnType<typeof _useHookState>) => T,\n deps?: any\n): T => {\n const state = _useHookState(hook);\n const { prevState, state: newState } = state;\n const idx = newState.length;\n const changed = prevState?.[idx]?.hook !== hook || !equalDeps(prevState[idx].deps, deps);\n const data = changed ? factory(state) : prevState[idx].data;\n newState.push({\n deps,\n hook,\n data\n });\n return data;\n};\n","//\n// memo.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { _useMemo } from '../reconciler/hooks';\n\n/**\n * A hook that memoizes a callback function, ensuring that it only changes\n * if its dependencies change. This is useful for optimizing performance by preventing\n * unnecessary re-creations of functions.\n *\n * @template T - The type of the callback function.\n * @param callback - The callback function to be memoized.\n * @param deps - An optional dependencies. If provided, the callback\n * will only be updated when one of these dependencies changes.\n * If not provided, the callback will remain stable.\n * @returns - A stable version of the callback function that will not change unless\n * its dependencies change.\n *\n * @example\n * const memoizedCallback = useCallback(() => {\n * console.log('This function is memoized!');\n * }, [dependency]);\n */\n\nexport function useCallback<T extends (...args: any) => any>(\n callback: T,\n deps?: any\n): T;\n\nexport function useCallback<T extends ((...args: any) => any) | _.Falsey>(\n callback: T,\n deps?: any\n): T;\n\nexport function useCallback<T extends ((...args: any) => any) | _.Falsey>(\n callback: T,\n deps?: any\n): T {\n if (!_.isUndefined(deps)) return _useMemo('useCallback', () => callback, deps);\n const store = _useMemo('useCallback', () => {\n const store = {\n current: callback,\n stable: (...args: any) => {\n if (store.current) return store.current(...args);\n },\n };\n return store;\n }, null);\n if (callback) store.current = callback;\n return callback && (store.stable as T);\n}\n","//\n// effect.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { Awaitable } from '@o2ter/utils-js';\nimport { _useEffect } from '../reconciler/hooks';\n\n/**\n * A hook that manages side effects with support for an `AbortSignal`.\n * It ensures proper cleanup logic and handles asynchronous operations effectively.\n *\n * @param effect - \n * A function that receives an `AbortSignal` and performs side effects. \n * It can optionally return a cleanup function or a promise that resolves to a cleanup function.\n *\n * @param deps - \n * An optional dependencies that determines when the effect should be re-executed.\n *\n * @example\n * useEffect((signal) => {\n * fetch('/api/data', { signal })\n * .then(response => response.json())\n * .then(data => console.log(data))\n * .catch(err => {\n * if (err.name === 'AbortError') {\n * console.log('Fetch aborted');\n * } else {\n * console.error(err);\n * }\n * });\n * \n * return () => {\n * console.log('Cleanup logic here');\n * };\n * }, []);\n */\nexport const useEffect = (\n effect: (\n signal: AbortSignal,\n ) => Awaitable<void | (() => Awaitable<void>)>,\n deps?: any,\n) => _useEffect('useEffect', () => {\n const abort = new AbortController();\n try {\n const destructor = effect(abort.signal);\n return () => {\n abort.abort();\n (async () => {\n try {\n const _destructor = await destructor;\n if (_.isFunction(_destructor)) _destructor();\n } catch (e) {\n console.error(e);\n }\n })();\n };\n } catch (e) {\n console.error(e);\n return () => abort.abort();\n }\n}, deps);","//\n// memo.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { _useMemo } from '../reconciler/hooks';\n\n/**\n * A utility function that memoizes the result of a factory function.\n * \n * @template T The type of the value returned by the factory function.\n * @param factory A function that produces a value to be memoized.\n * @param deps An optional dependency array. The memoized value is recalculated \n * only when the dependencies change.\n * @returns The memoized value produced by the factory function.\n */\nexport const useMemo = <T>(\n factory: () => T,\n deps?: any,\n) => _useMemo('useMemo', () => factory(), deps);\n","//\n// sync.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { Awaitable } from '@o2ter/utils-js';\nimport { _useEffect } from '../reconciler/hooks';\nimport { reconciler } from '../reconciler/state';\n\n/**\n * A hook utility for synchronizing with an external store.\n *\n * @template Snapshot - The type of the snapshot returned by the store.\n * @param subscribe - A function that sets up a subscription to the external store.\n * - `onStoreChange`: A callback to invoke when the store changes.\n * - `signal`: An `AbortSignal` to handle cleanup when the subscription is no longer needed.\n * - Returns an optional cleanup function or a promise resolving to one.\n * @param getSnapshot - A function that retrieves the current snapshot of the store.\n * @param getServerSnapshot - (Optional) A function that retrieves the snapshot of the store\n * in a server environment.\n * @returns The current snapshot of the store.\n *\n * @throws Will throw an error if used outside of a valid render context.\n */\nexport const useSyncExternalStore = <Snapshot>(\n subscribe: (\n onStoreChange: () => void,\n signal: AbortSignal,\n ) => Awaitable<void | (() => Awaitable<void>)>,\n getSnapshot: () => Snapshot,\n getServerSnapshot?: () => Snapshot,\n) => {\n const state = reconciler.currentHookState;\n if (!state) throw Error('useSyncExternalStore must be used within a render function.');\n _useEffect('useSyncExternalStore', ({ node }) => {\n const abort = new AbortController();\n try {\n const destructor = subscribe(() => { node?._setDirty(); }, abort.signal);\n return () => {\n abort.abort();\n (async () => {\n try {\n const _destructor = await destructor;\n if (_.isFunction(_destructor)) _destructor();\n } catch (e) {\n console.error(e);\n }\n })();\n };\n } catch (e) {\n console.error(e);\n return () => abort.abort();\n }\n }, null);\n if (getServerSnapshot && state.renderer._server) {\n return getServerSnapshot();\n }\n return getSnapshot();\n};"],"names":[],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMA,MAAM,aAAa,GAAG,CAAC,IAAY,KAAI;AACrC,IAAA,MAAM,KAAK,GAAG,UAAU,CAAC,gBAAgB;AACzC,IAAA,IAAI,CAAC,KAAK;AAAE,QAAA,MAAM,KAAK,CAAC,CAAA,EAAG,IAAI,CAAA,uCAAA,CAAyC,CAAC;IACzE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK;AAC5C,IAAA,IAAI,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,KAAK,IAAI,EAAE;QAC1D,OAAO,CAAC,IAAI,CAAC;AACX,YAAA,CAAA,MAAA,E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AE;AACV,wBAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;;iBAEnB,GAAG;AACN,aAAC;;QACD,OAAO,CAAC,EAAE;AACV,YAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAChB,YAAA,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE;;KAE7B,EAAE,IAAI,CAAC;IACR,IAAI,iBAAiB,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE;QAC/C,OAAO,iBAAiB,EAAE;;IAE5B,OAAO,WAAW,EAAE;AACtB;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frosty",
3
- "version": "0.0.55",
3
+ "version": "0.0.56",
4
4
  "main": "dist/index",
5
5
  "module": "dist/index",
6
6
  "types": "dist/index",