@dxos/react-async 0.6.9 → 0.6.10-main.3cfcc89
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/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/useAsyncEffect.d.ts +2 -2
- package/dist/types/src/useDebugReactDeps.d.ts.map +1 -1
- package/dist/types/src/useMulticastObservable.d.ts.map +1 -1
- package/package.json +3 -4
- package/src/index.ts +2 -0
- package/src/useAsyncEffect.ts +3 -3
- package/src/useDebugReactDeps.ts +2 -0
- package/src/useMulticastObservable.ts +1 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/useAsyncEffect.ts", "../../../src/useDebugReactDeps.ts", "../../../src/useMulticastObservable.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { useEffect } from 'react';\n\n/**\n * Process async event with optional non-async destructor.\n * Inspired by: https://github.com/rauldeheer/use-async-effect/blob/master/index.js\n *\n * ```tsx\n * useAsyncEffect(async () => {\n * await test();\n * }, []);\n * ```\n *\n * The callback may check of the component is still mounted before doing state updates.\n *\n * ```tsx\n * const [value, setValue] = useState<string>();\n * useAsyncEffect<string>(async (isMounted) => {\n * const value = await test();\n * if (!isMounted()) {\n * setValue(value);\n * }\n * }, () => console.log('Unmounted'), []);\n * ```\n *\n * @param callback Receives a getter function that determines if the
|
|
5
|
-
"mappings": ";AAIA,SAASA,iBAAiB;AA6BnB,IAAMC,iBAAiB,CAC5BC,UACAC,YACAC,SAAAA;AAEA,QAAM,CAACC,kBAAkBC,UAAAA,IACvB,OAAOH,eAAe,aAAa;IAACA;IAAYC;MAAQ;IAACG;IAAWJ;;AAEtEK,YAAU,MAAA;AACR,QAAIC,UAAU;AACd,QAAIC;AACJ,UAAMC,cAAcT,SAAS,MAAMO,OAAAA;AAGnC,SAAKG,QAAQC,QAAQF,WAAAA,EAAaG,KAAK,CAACC,WAAAA;AACtCL,cAAQK;IACV,CAAA;AAEA,WAAO,MAAA;AACLN,gBAAU;AACVJ,yBAAmBK,KAAAA;IACrB;EACF,GAAGJ,UAAAA;AACL;;;
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { useEffect } from 'react';\n\n/**\n * Process async event with optional non-async destructor.\n * Inspired by: https://github.com/rauldeheer/use-async-effect/blob/master/index.js\n *\n * ```tsx\n * useAsyncEffect(async () => {\n * await test();\n * }, []);\n * ```\n *\n * The callback may check of the component is still mounted before doing state updates.\n *\n * ```tsx\n * const [value, setValue] = useState<string>();\n * useAsyncEffect<string>(async (isMounted) => {\n * const value = await test();\n * if (!isMounted()) {\n * setValue(value);\n * }\n * }, () => console.log('Unmounted'), []);\n * ```\n *\n * @param callback Receives a getter function that determines if the component is still mounted.\n * @param destructor Receives the value returned from the callback.\n * @param deps\n */\n// TODO(burdon): Move to @dxos/react-ui.\nexport const useAsyncEffect = <T>(\n callback: (isMounted: () => boolean) => Promise<T> | undefined,\n destructor?: ((value?: T) => void) | any[],\n deps?: any[],\n) => {\n const [effectDestructor, effectDeps] =\n typeof destructor === 'function' ? [destructor, deps] : [undefined, destructor];\n\n useEffect(() => {\n let mounted = true;\n let value: T | undefined;\n const asyncResult = callback(() => mounted);\n\n // TODO(burdon): Catch exception.\n void Promise.resolve(asyncResult).then((result) => {\n value = result;\n });\n\n return () => {\n mounted = false;\n effectDestructor?.(value);\n };\n }, effectDeps);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/* eslint-disable no-console */\n\nimport { type DependencyList, useEffect, useRef } from 'react';\n\n/**\n * Util to log deps that have changed.\n */\n// TODO(burdon): Move to @dxos/react-ui.\nexport const useDebugReactDeps = (deps: DependencyList = []) => {\n const lastDeps = useRef<DependencyList>([]);\n useEffect(() => {\n console.group('deps changed', { old: lastDeps.current.length, new: deps.length });\n for (let i = 0; i < Math.max(lastDeps.current.length ?? 0, deps.length ?? 0); i++) {\n console.log(i, lastDeps.current[i] === deps[i] ? 'SAME' : 'CHANGED', {\n previous: lastDeps.current[i],\n current: deps[i],\n });\n }\n\n console.groupEnd();\n lastDeps.current = deps;\n }, deps);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type MulticastObservable } from '@dxos/async';\n\n/**\n * Subscribe to a MulticastObservable and return the latest value.\n * @param observable the observable to subscribe to. Will resubscribe if the observable changes.\n */\n// TODO(burdon): Move to @dxos/react-ui.\nexport const useMulticastObservable = <T>(observable: MulticastObservable<T>): T => {\n // Make sure useSyncExternalStore is stable in respect to the observable.\n const subscribeFn = useMemo(\n () => (listener: () => void) => {\n const subscription = observable.subscribe(listener);\n return () => subscription.unsubscribe();\n },\n [observable],\n );\n\n // useSyncExternalStore will resubscribe to the observable and update the value if the subscribeFn changes.\n return useSyncExternalStore(subscribeFn, () => observable.get());\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,iBAAiB;AA6BnB,IAAMC,iBAAiB,CAC5BC,UACAC,YACAC,SAAAA;AAEA,QAAM,CAACC,kBAAkBC,UAAAA,IACvB,OAAOH,eAAe,aAAa;IAACA;IAAYC;MAAQ;IAACG;IAAWJ;;AAEtEK,YAAU,MAAA;AACR,QAAIC,UAAU;AACd,QAAIC;AACJ,UAAMC,cAAcT,SAAS,MAAMO,OAAAA;AAGnC,SAAKG,QAAQC,QAAQF,WAAAA,EAAaG,KAAK,CAACC,WAAAA;AACtCL,cAAQK;IACV,CAAA;AAEA,WAAO,MAAA;AACLN,gBAAU;AACVJ,yBAAmBK,KAAAA;IACrB;EACF,GAAGJ,UAAAA;AACL;;;AClDA,SAA8BU,aAAAA,YAAWC,cAAc;AAMhD,IAAMC,oBAAoB,CAACC,OAAuB,CAAA,MAAE;AACzD,QAAMC,WAAWC,OAAuB,CAAA,CAAE;AAC1CC,EAAAA,WAAU,MAAA;AACRC,YAAQC,MAAM,gBAAgB;MAAEC,KAAKL,SAASM,QAAQC;MAAQC,KAAKT,KAAKQ;IAAO,CAAA;AAC/E,aAASE,IAAI,GAAGA,IAAIC,KAAKC,IAAIX,SAASM,QAAQC,UAAU,GAAGR,KAAKQ,UAAU,CAAA,GAAIE,KAAK;AACjFN,cAAQS,IAAIH,GAAGT,SAASM,QAAQG,CAAAA,MAAOV,KAAKU,CAAAA,IAAK,SAAS,WAAW;QACnEI,UAAUb,SAASM,QAAQG,CAAAA;QAC3BH,SAASP,KAAKU,CAAAA;MAChB,CAAA;IACF;AAEAN,YAAQW,SAAQ;AAChBd,aAASM,UAAUP;EACrB,GAAGA,IAAAA;AACL;;;ACtBA,SAASgB,SAASC,4BAA4B;AASvC,IAAMC,yBAAyB,CAAIC,eAAAA;AAExC,QAAMC,cAAcC,QAClB,MAAM,CAACC,aAAAA;AACL,UAAMC,eAAeJ,WAAWK,UAAUF,QAAAA;AAC1C,WAAO,MAAMC,aAAaE,YAAW;EACvC,GACA;IAACN;GAAW;AAId,SAAOO,qBAAqBN,aAAa,MAAMD,WAAWQ,IAAG,CAAA;AAC/D;",
|
|
6
6
|
"names": ["useEffect", "useAsyncEffect", "callback", "destructor", "deps", "effectDestructor", "effectDeps", "undefined", "useEffect", "mounted", "value", "asyncResult", "Promise", "resolve", "then", "result", "useEffect", "useRef", "useDebugReactDeps", "deps", "lastDeps", "useRef", "useEffect", "console", "group", "old", "current", "length", "new", "i", "Math", "max", "log", "previous", "groupEnd", "useMemo", "useSyncExternalStore", "useMulticastObservable", "observable", "subscribeFn", "useMemo", "listener", "subscription", "subscribe", "unsubscribe", "useSyncExternalStore", "get"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/common/react-async/src/useAsyncEffect.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/common/react-async/src/useAsyncEffect.ts":{"bytes":4777,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"packages/common/react-async/src/useDebugReactDeps.ts":{"bytes":3192,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"packages/common/react-async/src/useMulticastObservable.ts":{"bytes":3033,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"packages/common/react-async/src/index.ts":{"bytes":889,"imports":[{"path":"packages/common/react-async/src/useAsyncEffect.ts","kind":"import-statement","original":"./useAsyncEffect"},{"path":"packages/common/react-async/src/useDebugReactDeps.ts","kind":"import-statement","original":"./useDebugReactDeps"},{"path":"packages/common/react-async/src/useMulticastObservable.ts","kind":"import-statement","original":"./useMulticastObservable"}],"format":"esm"}},"outputs":{"packages/common/react-async/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5202},"packages/common/react-async/dist/lib/browser/index.mjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["useAsyncEffect","useDebugReactDeps","useMulticastObservable"],"entryPoint":"packages/common/react-async/src/index.ts","inputs":{"packages/common/react-async/src/useAsyncEffect.ts":{"bytesInOutput":531},"packages/common/react-async/src/index.ts":{"bytesInOutput":0},"packages/common/react-async/src/useDebugReactDeps.ts":{"bytesInOutput":567},"packages/common/react-async/src/useMulticastObservable.ts":{"bytesInOutput":355}},"bytes":1736}}}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/useAsyncEffect.ts", "../../../src/useDebugReactDeps.ts", "../../../src/useMulticastObservable.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { useEffect } from 'react';\n\n/**\n * Process async event with optional non-async destructor.\n * Inspired by: https://github.com/rauldeheer/use-async-effect/blob/master/index.js\n *\n * ```tsx\n * useAsyncEffect(async () => {\n * await test();\n * }, []);\n * ```\n *\n * The callback may check of the component is still mounted before doing state updates.\n *\n * ```tsx\n * const [value, setValue] = useState<string>();\n * useAsyncEffect<string>(async (isMounted) => {\n * const value = await test();\n * if (!isMounted()) {\n * setValue(value);\n * }\n * }, () => console.log('Unmounted'), []);\n * ```\n *\n * @param callback Receives a getter function that determines if the
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAA0B;
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { useEffect } from 'react';\n\n/**\n * Process async event with optional non-async destructor.\n * Inspired by: https://github.com/rauldeheer/use-async-effect/blob/master/index.js\n *\n * ```tsx\n * useAsyncEffect(async () => {\n * await test();\n * }, []);\n * ```\n *\n * The callback may check of the component is still mounted before doing state updates.\n *\n * ```tsx\n * const [value, setValue] = useState<string>();\n * useAsyncEffect<string>(async (isMounted) => {\n * const value = await test();\n * if (!isMounted()) {\n * setValue(value);\n * }\n * }, () => console.log('Unmounted'), []);\n * ```\n *\n * @param callback Receives a getter function that determines if the component is still mounted.\n * @param destructor Receives the value returned from the callback.\n * @param deps\n */\n// TODO(burdon): Move to @dxos/react-ui.\nexport const useAsyncEffect = <T>(\n callback: (isMounted: () => boolean) => Promise<T> | undefined,\n destructor?: ((value?: T) => void) | any[],\n deps?: any[],\n) => {\n const [effectDestructor, effectDeps] =\n typeof destructor === 'function' ? [destructor, deps] : [undefined, destructor];\n\n useEffect(() => {\n let mounted = true;\n let value: T | undefined;\n const asyncResult = callback(() => mounted);\n\n // TODO(burdon): Catch exception.\n void Promise.resolve(asyncResult).then((result) => {\n value = result;\n });\n\n return () => {\n mounted = false;\n effectDestructor?.(value);\n };\n }, effectDeps);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/* eslint-disable no-console */\n\nimport { type DependencyList, useEffect, useRef } from 'react';\n\n/**\n * Util to log deps that have changed.\n */\n// TODO(burdon): Move to @dxos/react-ui.\nexport const useDebugReactDeps = (deps: DependencyList = []) => {\n const lastDeps = useRef<DependencyList>([]);\n useEffect(() => {\n console.group('deps changed', { old: lastDeps.current.length, new: deps.length });\n for (let i = 0; i < Math.max(lastDeps.current.length ?? 0, deps.length ?? 0); i++) {\n console.log(i, lastDeps.current[i] === deps[i] ? 'SAME' : 'CHANGED', {\n previous: lastDeps.current[i],\n current: deps[i],\n });\n }\n\n console.groupEnd();\n lastDeps.current = deps;\n }, deps);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type MulticastObservable } from '@dxos/async';\n\n/**\n * Subscribe to a MulticastObservable and return the latest value.\n * @param observable the observable to subscribe to. Will resubscribe if the observable changes.\n */\n// TODO(burdon): Move to @dxos/react-ui.\nexport const useMulticastObservable = <T>(observable: MulticastObservable<T>): T => {\n // Make sure useSyncExternalStore is stable in respect to the observable.\n const subscribeFn = useMemo(\n () => (listener: () => void) => {\n const subscription = observable.subscribe(listener);\n return () => subscription.unsubscribe();\n },\n [observable],\n );\n\n // useSyncExternalStore will resubscribe to the observable and update the value if the subscribeFn changes.\n return useSyncExternalStore(subscribeFn, () => observable.get());\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAA0B;ACE1B,IAAAA,gBAAuD;ACFvD,IAAAA,gBAA8C;AF6BvC,IAAMC,iBAAiB,CAC5BC,UACAC,YACAC,SAAAA;AAEA,QAAM,CAACC,kBAAkBC,UAAAA,IACvB,OAAOH,eAAe,aAAa;IAACA;IAAYC;MAAQ;IAACG;IAAWJ;;AAEtEK,8BAAU,MAAA;AACR,QAAIC,UAAU;AACd,QAAIC;AACJ,UAAMC,cAAcT,SAAS,MAAMO,OAAAA;AAGnC,SAAKG,QAAQC,QAAQF,WAAAA,EAAaG,KAAK,CAACC,WAAAA;AACtCL,cAAQK;IACV,CAAA;AAEA,WAAO,MAAA;AACLN,gBAAU;AACVJ,yBAAmBK,KAAAA;IACrB;EACF,GAAGJ,UAAAA;AACL;AC5CO,IAAMU,oBAAoB,CAACZ,OAAuB,CAAA,MAAE;AACzD,QAAMa,eAAWC,sBAAuB,CAAA,CAAE;AAC1CV,oBAAAA,WAAU,MAAA;AACRW,YAAQC,MAAM,gBAAgB;MAAEC,KAAKJ,SAASK,QAAQC;MAAQC,KAAKpB,KAAKmB;IAAO,CAAA;AAC/E,aAASE,IAAI,GAAGA,IAAIC,KAAKC,IAAIV,SAASK,QAAQC,UAAU,GAAGnB,KAAKmB,UAAU,CAAA,GAAIE,KAAK;AACjFN,cAAQS,IAAIH,GAAGR,SAASK,QAAQG,CAAAA,MAAOrB,KAAKqB,CAAAA,IAAK,SAAS,WAAW;QACnEI,UAAUZ,SAASK,QAAQG,CAAAA;QAC3BH,SAASlB,KAAKqB,CAAAA;MAChB,CAAA;IACF;AAEAN,YAAQW,SAAQ;AAChBb,aAASK,UAAUlB;EACrB,GAAGA,IAAAA;AACL;ACbO,IAAM2B,yBAAyB,CAAIC,eAAAA;AAExC,QAAMC,kBAAcC,uBAClB,MAAM,CAACC,aAAAA;AACL,UAAMC,eAAeJ,WAAWK,UAAUF,QAAAA;AAC1C,WAAO,MAAMC,aAAaE,YAAW;EACvC,GACA;IAACN;GAAW;AAId,aAAOO,oCAAqBN,aAAa,MAAMD,WAAWQ,IAAG,CAAA;AAC/D;",
|
|
6
6
|
"names": ["import_react", "useAsyncEffect", "callback", "destructor", "deps", "effectDestructor", "effectDeps", "undefined", "useEffect", "mounted", "value", "asyncResult", "Promise", "resolve", "then", "result", "useDebugReactDeps", "lastDeps", "useRef", "console", "group", "old", "current", "length", "new", "i", "Math", "max", "log", "previous", "groupEnd", "useMulticastObservable", "observable", "subscribeFn", "useMemo", "listener", "subscription", "subscribe", "unsubscribe", "useSyncExternalStore", "get"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/common/react-async/src/useAsyncEffect.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/common/react-async/src/useAsyncEffect.ts":{"bytes":4777,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"packages/common/react-async/src/useDebugReactDeps.ts":{"bytes":3192,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"packages/common/react-async/src/useMulticastObservable.ts":{"bytes":3033,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"packages/common/react-async/src/index.ts":{"bytes":889,"imports":[{"path":"packages/common/react-async/src/useAsyncEffect.ts","kind":"import-statement","original":"./useAsyncEffect"},{"path":"packages/common/react-async/src/useDebugReactDeps.ts","kind":"import-statement","original":"./useDebugReactDeps"},{"path":"packages/common/react-async/src/useMulticastObservable.ts","kind":"import-statement","original":"./useMulticastObservable"}],"format":"esm"}},"outputs":{"packages/common/react-async/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5202},"packages/common/react-async/dist/lib/node/index.cjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["useAsyncEffect","useDebugReactDeps","useMulticastObservable"],"entryPoint":"packages/common/react-async/src/index.ts","inputs":{"packages/common/react-async/src/useAsyncEffect.ts":{"bytesInOutput":531},"packages/common/react-async/src/index.ts":{"bytesInOutput":0},"packages/common/react-async/src/useDebugReactDeps.ts":{"bytesInOutput":567},"packages/common/react-async/src/useMulticastObservable.ts":{"bytesInOutput":355}},"bytes":1736}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC"}
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
* }, () => console.log('Unmounted'), []);
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
|
-
* @param callback Receives a getter function that determines if the
|
|
24
|
-
* @param destructor Receives the value
|
|
23
|
+
* @param callback Receives a getter function that determines if the component is still mounted.
|
|
24
|
+
* @param destructor Receives the value returned from the callback.
|
|
25
25
|
* @param deps
|
|
26
26
|
*/
|
|
27
27
|
export declare const useAsyncEffect: <T>(callback: (isMounted: () => boolean) => Promise<T> | undefined, destructor?: ((value?: T) => void) | any[], deps?: any[]) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDebugReactDeps.d.ts","sourceRoot":"","sources":["../../../src/useDebugReactDeps.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDebugReactDeps.d.ts","sourceRoot":"","sources":["../../../src/useDebugReactDeps.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,OAAO,CAAC;AAE/D;;GAEG;AAEH,eAAO,MAAM,iBAAiB,UAAU,cAAc,SAcrD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMulticastObservable.d.ts","sourceRoot":"","sources":["../../../src/useMulticastObservable.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD;;;GAGG;
|
|
1
|
+
{"version":3,"file":"useMulticastObservable.d.ts","sourceRoot":"","sources":["../../../src/useMulticastObservable.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD;;;GAGG;AAEH,eAAO,MAAM,sBAAsB,GAAI,CAAC,cAAc,mBAAmB,CAAC,CAAC,CAAC,KAAG,CAY9E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-async",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10-main.3cfcc89",
|
|
4
4
|
"description": "Async utils",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
"src"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"
|
|
28
|
-
"@dxos/async": "0.6.9"
|
|
27
|
+
"@dxos/async": "0.6.10-main.3cfcc89"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
30
|
"@dxos/esbuild-server": "~2.29.0",
|
|
@@ -33,7 +32,7 @@
|
|
|
33
32
|
"@types/react-dom": "~18.2.0",
|
|
34
33
|
"react": "~18.2.0",
|
|
35
34
|
"react-dom": "~18.2.0",
|
|
36
|
-
"@dxos/esbuild-plugins": "0.6.
|
|
35
|
+
"@dxos/esbuild-plugins": "0.6.10-main.3cfcc89"
|
|
37
36
|
},
|
|
38
37
|
"peerDependencies": {
|
|
39
38
|
"react": "~18.2.0",
|
package/src/index.ts
CHANGED
package/src/useAsyncEffect.ts
CHANGED
|
@@ -26,11 +26,11 @@ import { useEffect } from 'react';
|
|
|
26
26
|
* }, () => console.log('Unmounted'), []);
|
|
27
27
|
* ```
|
|
28
28
|
*
|
|
29
|
-
* @param callback Receives a getter function that determines if the
|
|
30
|
-
* @param destructor Receives the value
|
|
29
|
+
* @param callback Receives a getter function that determines if the component is still mounted.
|
|
30
|
+
* @param destructor Receives the value returned from the callback.
|
|
31
31
|
* @param deps
|
|
32
32
|
*/
|
|
33
|
-
// TODO(burdon):
|
|
33
|
+
// TODO(burdon): Move to @dxos/react-ui.
|
|
34
34
|
export const useAsyncEffect = <T>(
|
|
35
35
|
callback: (isMounted: () => boolean) => Promise<T> | undefined,
|
|
36
36
|
destructor?: ((value?: T) => void) | any[],
|
package/src/useDebugReactDeps.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
|
+
|
|
4
5
|
/* eslint-disable no-console */
|
|
5
6
|
|
|
6
7
|
import { type DependencyList, useEffect, useRef } from 'react';
|
|
@@ -8,6 +9,7 @@ import { type DependencyList, useEffect, useRef } from 'react';
|
|
|
8
9
|
/**
|
|
9
10
|
* Util to log deps that have changed.
|
|
10
11
|
*/
|
|
12
|
+
// TODO(burdon): Move to @dxos/react-ui.
|
|
11
13
|
export const useDebugReactDeps = (deps: DependencyList = []) => {
|
|
12
14
|
const lastDeps = useRef<DependencyList>([]);
|
|
13
15
|
useEffect(() => {
|
|
@@ -10,6 +10,7 @@ import { type MulticastObservable } from '@dxos/async';
|
|
|
10
10
|
* Subscribe to a MulticastObservable and return the latest value.
|
|
11
11
|
* @param observable the observable to subscribe to. Will resubscribe if the observable changes.
|
|
12
12
|
*/
|
|
13
|
+
// TODO(burdon): Move to @dxos/react-ui.
|
|
13
14
|
export const useMulticastObservable = <T>(observable: MulticastObservable<T>): T => {
|
|
14
15
|
// Make sure useSyncExternalStore is stable in respect to the observable.
|
|
15
16
|
const subscribeFn = useMemo(
|