@assistant-ui/react 0.7.47 → 0.7.48
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/context/providers/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.js +1 -0
- package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.mjs +1 -0
- package/dist/context/providers/AssistantRuntimeProvider.mjs.map +1 -1
- package/dist/context/react/utils/useRuntimeState.d.ts.map +1 -1
- package/dist/context/react/utils/useRuntimeState.js +1 -1
- package/dist/context/react/utils/useRuntimeState.js.map +1 -1
- package/dist/context/react/utils/useRuntimeState.mjs +1 -1
- package/dist/context/react/utils/useRuntimeState.mjs.map +1 -1
- package/package.json +1 -1
- package/src/context/providers/AssistantRuntimeProvider.tsx +2 -1
- package/src/context/react/utils/useRuntimeState.ts +4 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AssistantRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,EAAE,EACF,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAM9D,yBAAiB,wBAAwB,CAAC;IACxC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC;;WAEG;QACH,OAAO,EAAE,gBAAgB,CAAC;KAC3B,CAAC,CAAC;CACJ;
|
1
|
+
{"version":3,"file":"AssistantRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,EAAE,EACF,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAM9D,yBAAiB,wBAAwB,CAAC;IACxC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC;;WAEG;QACH,OAAO,EAAE,gBAAgB,CAAC;KAC3B,CAAC,CAAC;CACJ;AAuBD,eAAO,MAAM,4BAA4B,EAAE,EAAE,CAC3C,wBAAwB,CAAC,KAAK,CAwB/B,CAAC;AAEF,eAAO,MAAM,wBAAwB,sEAAqC,CAAC"}
|
@@ -37,6 +37,7 @@ var useAssistantRuntimeStore = (runtime) => {
|
|
37
37
|
const [store] = (0, import_react.useState)(() => (0, import_zustand.create)(() => runtime));
|
38
38
|
(0, import_react.useEffect)(() => {
|
39
39
|
(0, import_ensureBinding.ensureBinding)(runtime);
|
40
|
+
(0, import_ensureBinding.ensureBinding)(runtime.threads);
|
40
41
|
(0, import_ReadonlyStore.writableStore)(store).setState(runtime, true);
|
41
42
|
}, [runtime, store]);
|
42
43
|
return store;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n memo,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AssistantRuntimeCore } from \"../../runtimes/core/AssistantRuntimeCore\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n
|
1
|
+
{"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n memo,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AssistantRuntimeCore } from \"../../runtimes/core/AssistantRuntimeCore\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n ensureBinding(runtime.threads);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useAssistantToolUIsStore = () => {\n return useMemo(() => makeAssistantToolUIsStore(), []);\n};\n\nconst getRenderComponent = (runtime: AssistantRuntime) => {\n return (runtime as { _core?: AssistantRuntimeCore })._core?.RenderComponent;\n};\n\nexport const AssistantRuntimeProviderImpl: FC<\n AssistantRuntimeProvider.Props\n> = ({ children, runtime }) => {\n const useAssistantRuntime = useAssistantRuntimeStore(runtime);\n const useToolUIs = useAssistantToolUIsStore();\n const [context] = useState(() => {\n return {\n useToolUIs,\n useAssistantRuntime,\n };\n });\n\n const RenderComponent = getRenderComponent(runtime);\n\n return (\n <AssistantContext.Provider value={context}>\n {RenderComponent && <RenderComponent />}\n <ThreadRuntimeProvider\n runtime={runtime.thread}\n listItemRuntime={runtime.threadList.mainItem}\n >\n {children}\n </ThreadRuntimeProvider>\n </AssistantContext.Provider>\n );\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAOO;AACP,8BAAiC;AACjC,8BAA0C;AAC1C,mCAAsC;AAEtC,qBAAuB;AACvB,2BAA8B;AAE9B,2BAA8B;AA+C1B;AApCJ,IAAM,2BAA2B,CAAC,YAA8B;AAC9D,QAAM,CAAC,KAAK,QAAI,uBAAS,UAAM,uBAAO,MAAM,OAAO,CAAC;AAEpD,8BAAU,MAAM;AACd,4CAAc,OAAO;AACrB,4CAAc,QAAQ,OAAO;AAE7B,4CAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,2BAA2B,MAAM;AACrC,aAAO,sBAAQ,UAAM,mDAA0B,GAAG,CAAC,CAAC;AACtD;AAEA,IAAM,qBAAqB,CAAC,YAA8B;AACxD,SAAQ,QAA6C,OAAO;AAC9D;AAEO,IAAM,+BAET,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC7B,QAAM,sBAAsB,yBAAyB,OAAO;AAC5D,QAAM,aAAa,yBAAyB;AAC5C,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM;AAC/B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AAED,QAAM,kBAAkB,mBAAmB,OAAO;AAElD,SACE,6CAAC,yCAAiB,UAAjB,EAA0B,OAAO,SAC/B;AAAA,uBAAmB,4CAAC,mBAAgB;AAAA,IACrC;AAAA,MAAC;AAAA;AAAA,QACC,SAAS,QAAQ;AAAA,QACjB,iBAAiB,QAAQ,WAAW;AAAA,QAEnC;AAAA;AAAA,IACH;AAAA,KACF;AAEJ;AAEO,IAAM,+BAA2B,mBAAK,4BAA4B;","names":[]}
|
@@ -18,6 +18,7 @@ var useAssistantRuntimeStore = (runtime) => {
|
|
18
18
|
const [store] = useState(() => create(() => runtime));
|
19
19
|
useEffect(() => {
|
20
20
|
ensureBinding(runtime);
|
21
|
+
ensureBinding(runtime.threads);
|
21
22
|
writableStore(store).setState(runtime, true);
|
22
23
|
}, [runtime, store]);
|
23
24
|
return store;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n memo,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AssistantRuntimeCore } from \"../../runtimes/core/AssistantRuntimeCore\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n
|
1
|
+
{"version":3,"sources":["../../../src/context/providers/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n memo,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadRuntimeProvider } from \"./ThreadRuntimeProvider\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { create } from \"zustand\";\nimport { writableStore } from \"../ReadonlyStore\";\nimport { AssistantRuntimeCore } from \"../../runtimes/core/AssistantRuntimeCore\";\nimport { ensureBinding } from \"../react/utils/ensureBinding\";\n\nexport namespace AssistantRuntimeProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst useAssistantRuntimeStore = (runtime: AssistantRuntime) => {\n const [store] = useState(() => create(() => runtime));\n\n useEffect(() => {\n ensureBinding(runtime);\n ensureBinding(runtime.threads);\n\n writableStore(store).setState(runtime, true);\n }, [runtime, store]);\n\n return store;\n};\n\nconst useAssistantToolUIsStore = () => {\n return useMemo(() => makeAssistantToolUIsStore(), []);\n};\n\nconst getRenderComponent = (runtime: AssistantRuntime) => {\n return (runtime as { _core?: AssistantRuntimeCore })._core?.RenderComponent;\n};\n\nexport const AssistantRuntimeProviderImpl: FC<\n AssistantRuntimeProvider.Props\n> = ({ children, runtime }) => {\n const useAssistantRuntime = useAssistantRuntimeStore(runtime);\n const useToolUIs = useAssistantToolUIsStore();\n const [context] = useState(() => {\n return {\n useToolUIs,\n useAssistantRuntime,\n };\n });\n\n const RenderComponent = getRenderComponent(runtime);\n\n return (\n <AssistantContext.Provider value={context}>\n {RenderComponent && <RenderComponent />}\n <ThreadRuntimeProvider\n runtime={runtime.thread}\n listItemRuntime={runtime.threadList.mainItem}\n >\n {children}\n </ThreadRuntimeProvider>\n </AssistantContext.Provider>\n );\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAEtC,SAAS,cAAc;AACvB,SAAS,qBAAqB;AAE9B,SAAS,qBAAqB;AA+C1B,SACsB,KADtB;AApCJ,IAAM,2BAA2B,CAAC,YAA8B;AAC9D,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC;AAEpD,YAAU,MAAM;AACd,kBAAc,OAAO;AACrB,kBAAc,QAAQ,OAAO;AAE7B,kBAAc,KAAK,EAAE,SAAS,SAAS,IAAI;AAAA,EAC7C,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,SAAO;AACT;AAEA,IAAM,2BAA2B,MAAM;AACrC,SAAO,QAAQ,MAAM,0BAA0B,GAAG,CAAC,CAAC;AACtD;AAEA,IAAM,qBAAqB,CAAC,YAA8B;AACxD,SAAQ,QAA6C,OAAO;AAC9D;AAEO,IAAM,+BAET,CAAC,EAAE,UAAU,QAAQ,MAAM;AAC7B,QAAM,sBAAsB,yBAAyB,OAAO;AAC5D,QAAM,aAAa,yBAAyB;AAC5C,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM;AAC/B,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AAED,QAAM,kBAAkB,mBAAmB,OAAO;AAElD,SACE,qBAAC,iBAAiB,UAAjB,EAA0B,OAAO,SAC/B;AAAA,uBAAmB,oBAAC,mBAAgB;AAAA,IACrC;AAAA,MAAC;AAAA;AAAA,QACC,SAAS,QAAQ;AAAA,QACjB,iBAAiB,QAAQ,WAAW;AAAA,QAEnC;AAAA;AAAA,IACH;AAAA,KACF;AAEJ;AAEO,IAAM,2BAA2B,KAAK,4BAA4B;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useRuntimeState.d.ts","sourceRoot":"","sources":["../../../../src/context/react/utils/useRuntimeState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,MAAM,MAAM,mBAAmB,CAAC,MAAM,IAAI;IACxC,QAAQ,EAAE,MAAM,MAAM,CAAC;IACvB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,WAAW,CAAC;CAClD,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,EACvD,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,EACpC,QAAQ,GAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,GAAG,SAA2B,GACrE,SAAS,GAAG,MAAM,
|
1
|
+
{"version":3,"file":"useRuntimeState.d.ts","sourceRoot":"","sources":["../../../../src/context/react/utils/useRuntimeState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,MAAM,MAAM,mBAAmB,CAAC,MAAM,IAAI;IACxC,QAAQ,EAAE,MAAM,MAAM,CAAC;IACvB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,WAAW,CAAC;CAClD,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,EACvD,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,EACpC,QAAQ,GAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,GAAG,SAA2B,GACrE,SAAS,GAAG,MAAM,CAWpB;AAGD,wBAAgB,eAAe,CAAC,MAAM,EACpC,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,GACnC,MAAM,CAAC;AACV,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAC/C,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,EACpC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,GACrC,SAAS,CAAC;AACb,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAC/C,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,EACpC,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,GAAG,SAAS,GACnD,SAAS,GAAG,MAAM,CAAC"}
|
@@ -27,6 +27,7 @@ module.exports = __toCommonJS(useRuntimeState_exports);
|
|
27
27
|
var import_react = require("react");
|
28
28
|
var import_ensureBinding = require("./ensureBinding.js");
|
29
29
|
function useRuntimeStateInternal(runtime, selector = identity) {
|
30
|
+
(0, import_ensureBinding.ensureBinding)(runtime);
|
30
31
|
const slice = (0, import_react.useSyncExternalStore)(
|
31
32
|
runtime.subscribe,
|
32
33
|
() => selector(runtime.getState()),
|
@@ -37,7 +38,6 @@ function useRuntimeStateInternal(runtime, selector = identity) {
|
|
37
38
|
}
|
38
39
|
var identity = (arg) => arg;
|
39
40
|
function useRuntimeState(runtime, selector) {
|
40
|
-
(0, import_ensureBinding.ensureBinding)(runtime);
|
41
41
|
return useRuntimeStateInternal(runtime, selector);
|
42
42
|
}
|
43
43
|
// Annotate the CommonJS export names for ESM import in node:
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/context/react/utils/useRuntimeState.ts"],"sourcesContent":["import { useDebugValue, useSyncExternalStore } from \"react\";\nimport { Unsubscribe } from \"../../../types\";\nimport { ensureBinding } from \"./ensureBinding\";\n\nexport type SubscribableRuntime<TState> = {\n getState: () => TState;\n subscribe: (callback: () => void) => Unsubscribe;\n};\n\nexport function useRuntimeStateInternal<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: ((state: TState) => TSelected) | undefined = identity as any,\n): TSelected | TState {\n const slice = useSyncExternalStore(\n runtime.subscribe,\n () => selector(runtime.getState()),\n () => selector(runtime.getState()),\n );\n useDebugValue(slice);\n return slice;\n}\n\nconst identity = <T>(arg: T): T => arg;\nexport function useRuntimeState<TState>(\n runtime: SubscribableRuntime<TState>,\n): TState;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: (state: TState) => TSelected,\n): TSelected;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: ((state: TState) => TSelected) | undefined,\n): TSelected | TState;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector?: ((state: TState) => TSelected) | undefined,\n): TSelected | TState {\n // ensure that the runtime is bound\n ensureBinding(runtime);\n\n return useRuntimeStateInternal(runtime, selector);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAoD;AAEpD,2BAA8B;AAOvB,SAAS,wBACd,SACA,WAAuD,UACnC;
|
1
|
+
{"version":3,"sources":["../../../../src/context/react/utils/useRuntimeState.ts"],"sourcesContent":["import { useDebugValue, useSyncExternalStore } from \"react\";\nimport { Unsubscribe } from \"../../../types\";\nimport { ensureBinding } from \"./ensureBinding\";\n\nexport type SubscribableRuntime<TState> = {\n getState: () => TState;\n subscribe: (callback: () => void) => Unsubscribe;\n};\n\nexport function useRuntimeStateInternal<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: ((state: TState) => TSelected) | undefined = identity as any,\n): TSelected | TState {\n // TODO move to useRuntimeState\n ensureBinding(runtime);\n\n const slice = useSyncExternalStore(\n runtime.subscribe,\n () => selector(runtime.getState()),\n () => selector(runtime.getState()),\n );\n useDebugValue(slice);\n return slice;\n}\n\nconst identity = <T>(arg: T): T => arg;\nexport function useRuntimeState<TState>(\n runtime: SubscribableRuntime<TState>,\n): TState;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: (state: TState) => TSelected,\n): TSelected;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: ((state: TState) => TSelected) | undefined,\n): TSelected | TState;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector?: ((state: TState) => TSelected) | undefined,\n): TSelected | TState {\n // ensure that the runtime is bound\n // ensureBinding(runtime);\n\n return useRuntimeStateInternal(runtime, selector);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAoD;AAEpD,2BAA8B;AAOvB,SAAS,wBACd,SACA,WAAuD,UACnC;AAEpB,0CAAc,OAAO;AAErB,QAAM,YAAQ;AAAA,IACZ,QAAQ;AAAA,IACR,MAAM,SAAS,QAAQ,SAAS,CAAC;AAAA,IACjC,MAAM,SAAS,QAAQ,SAAS,CAAC;AAAA,EACnC;AACA,kCAAc,KAAK;AACnB,SAAO;AACT;AAEA,IAAM,WAAW,CAAI,QAAc;AAY5B,SAAS,gBACd,SACA,UACoB;AAIpB,SAAO,wBAAwB,SAAS,QAAQ;AAClD;","names":[]}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
import { useDebugValue, useSyncExternalStore } from "react";
|
3
3
|
import { ensureBinding } from "./ensureBinding.mjs";
|
4
4
|
function useRuntimeStateInternal(runtime, selector = identity) {
|
5
|
+
ensureBinding(runtime);
|
5
6
|
const slice = useSyncExternalStore(
|
6
7
|
runtime.subscribe,
|
7
8
|
() => selector(runtime.getState()),
|
@@ -12,7 +13,6 @@ function useRuntimeStateInternal(runtime, selector = identity) {
|
|
12
13
|
}
|
13
14
|
var identity = (arg) => arg;
|
14
15
|
function useRuntimeState(runtime, selector) {
|
15
|
-
ensureBinding(runtime);
|
16
16
|
return useRuntimeStateInternal(runtime, selector);
|
17
17
|
}
|
18
18
|
export {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/context/react/utils/useRuntimeState.ts"],"sourcesContent":["import { useDebugValue, useSyncExternalStore } from \"react\";\nimport { Unsubscribe } from \"../../../types\";\nimport { ensureBinding } from \"./ensureBinding\";\n\nexport type SubscribableRuntime<TState> = {\n getState: () => TState;\n subscribe: (callback: () => void) => Unsubscribe;\n};\n\nexport function useRuntimeStateInternal<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: ((state: TState) => TSelected) | undefined = identity as any,\n): TSelected | TState {\n const slice = useSyncExternalStore(\n runtime.subscribe,\n () => selector(runtime.getState()),\n () => selector(runtime.getState()),\n );\n useDebugValue(slice);\n return slice;\n}\n\nconst identity = <T>(arg: T): T => arg;\nexport function useRuntimeState<TState>(\n runtime: SubscribableRuntime<TState>,\n): TState;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: (state: TState) => TSelected,\n): TSelected;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: ((state: TState) => TSelected) | undefined,\n): TSelected | TState;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector?: ((state: TState) => TSelected) | undefined,\n): TSelected | TState {\n // ensure that the runtime is bound\n ensureBinding(runtime);\n\n return useRuntimeStateInternal(runtime, selector);\n}\n"],"mappings":";AAAA,SAAS,eAAe,4BAA4B;AAEpD,SAAS,qBAAqB;AAOvB,SAAS,wBACd,SACA,WAAuD,UACnC;
|
1
|
+
{"version":3,"sources":["../../../../src/context/react/utils/useRuntimeState.ts"],"sourcesContent":["import { useDebugValue, useSyncExternalStore } from \"react\";\nimport { Unsubscribe } from \"../../../types\";\nimport { ensureBinding } from \"./ensureBinding\";\n\nexport type SubscribableRuntime<TState> = {\n getState: () => TState;\n subscribe: (callback: () => void) => Unsubscribe;\n};\n\nexport function useRuntimeStateInternal<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: ((state: TState) => TSelected) | undefined = identity as any,\n): TSelected | TState {\n // TODO move to useRuntimeState\n ensureBinding(runtime);\n\n const slice = useSyncExternalStore(\n runtime.subscribe,\n () => selector(runtime.getState()),\n () => selector(runtime.getState()),\n );\n useDebugValue(slice);\n return slice;\n}\n\nconst identity = <T>(arg: T): T => arg;\nexport function useRuntimeState<TState>(\n runtime: SubscribableRuntime<TState>,\n): TState;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: (state: TState) => TSelected,\n): TSelected;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector: ((state: TState) => TSelected) | undefined,\n): TSelected | TState;\nexport function useRuntimeState<TState, TSelected>(\n runtime: SubscribableRuntime<TState>,\n selector?: ((state: TState) => TSelected) | undefined,\n): TSelected | TState {\n // ensure that the runtime is bound\n // ensureBinding(runtime);\n\n return useRuntimeStateInternal(runtime, selector);\n}\n"],"mappings":";AAAA,SAAS,eAAe,4BAA4B;AAEpD,SAAS,qBAAqB;AAOvB,SAAS,wBACd,SACA,WAAuD,UACnC;AAEpB,gBAAc,OAAO;AAErB,QAAM,QAAQ;AAAA,IACZ,QAAQ;AAAA,IACR,MAAM,SAAS,QAAQ,SAAS,CAAC;AAAA,IACjC,MAAM,SAAS,QAAQ,SAAS,CAAC;AAAA,EACnC;AACA,gBAAc,KAAK;AACnB,SAAO;AACT;AAEA,IAAM,WAAW,CAAI,QAAc;AAY5B,SAAS,gBACd,SACA,UACoB;AAIpB,SAAO,wBAAwB,SAAS,QAAQ;AAClD;","names":[]}
|
package/package.json
CHANGED
@@ -11,6 +11,9 @@ export function useRuntimeStateInternal<TState, TSelected>(
|
|
11
11
|
runtime: SubscribableRuntime<TState>,
|
12
12
|
selector: ((state: TState) => TSelected) | undefined = identity as any,
|
13
13
|
): TSelected | TState {
|
14
|
+
// TODO move to useRuntimeState
|
15
|
+
ensureBinding(runtime);
|
16
|
+
|
14
17
|
const slice = useSyncExternalStore(
|
15
18
|
runtime.subscribe,
|
16
19
|
() => selector(runtime.getState()),
|
@@ -37,7 +40,7 @@ export function useRuntimeState<TState, TSelected>(
|
|
37
40
|
selector?: ((state: TState) => TSelected) | undefined,
|
38
41
|
): TSelected | TState {
|
39
42
|
// ensure that the runtime is bound
|
40
|
-
ensureBinding(runtime);
|
43
|
+
// ensureBinding(runtime);
|
41
44
|
|
42
45
|
return useRuntimeStateInternal(runtime, selector);
|
43
46
|
}
|