@ic-reactor/react 1.16.0 → 2.0.0
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/context/actor/create.js +19 -22
- package/dist/context/actor/hooks/useActorInterface.d.ts +1 -1
- package/dist/context/actor/hooks/useMethod.d.ts +3 -3
- package/dist/context/actor/hooks/useMethod.js +3 -3
- package/dist/context/actor/hooks/useQueryCall.d.ts +2 -2
- package/dist/context/actor/hooks/useQueryCall.js +2 -2
- package/dist/context/actor/hooks/useUpdateCall.d.ts +3 -3
- package/dist/context/actor/hooks/useUpdateCall.js +3 -3
- package/dist/context/actor/hooks/useVisitMethod.d.ts +1 -1
- package/dist/context/adapter/create.d.ts +2 -2
- package/dist/context/adapter/create.js +23 -30
- package/dist/context/adapter/index.d.ts +1 -1
- package/dist/context/adapter/types.d.ts +33 -6
- package/dist/context/agent/create.js +10 -17
- package/dist/createReactor.js +7 -2
- package/dist/helpers/actorHooks.js +77 -66
- package/dist/helpers/authHooks.js +46 -44
- package/dist/helpers/extractActorContext.js +1 -1
- package/dist/helpers/types.d.ts +123 -13
- package/dist/hooks/types.d.ts +2 -2
- package/dist/hooks/useActor.js +36 -38
- package/dist/index.js +17 -7
- package/dist/types.d.ts +1 -2
- package/package.json +17 -24
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
@@ -80,29 +69,34 @@ const useActorManager_1 = require("../../hooks/useActorManager");
|
|
|
80
69
|
* it provides a type-safe and efficient way to manage actor state and interactions.
|
|
81
70
|
*/
|
|
82
71
|
function createActorContext(contextConfig = {}) {
|
|
83
|
-
const { canisterId: defaultCanisterId
|
|
72
|
+
const { canisterId: defaultCanisterId, ...defaultConfig } = contextConfig;
|
|
84
73
|
const ActorContext = react_1.default.createContext(null);
|
|
85
|
-
const ActorProvider = (
|
|
86
|
-
var { children, fetchingComponent, canisterId = defaultCanisterId, errorComponent = (error) => react_1.default.createElement("div", null, error), loadingComponent = react_1.default.createElement("div", null, "Loading canister..."), authenticatingComponent = react_1.default.createElement("div", null, "Authenticating...") } = _a, restConfig = __rest(_a, ["children", "fetchingComponent", "canisterId", "errorComponent", "loadingComponent", "authenticatingComponent"]);
|
|
74
|
+
const ActorProvider = ({ children, fetchingComponent, canisterId = defaultCanisterId, errorComponent = (error) => react_1.default.createElement("div", null, error), loadingComponent = react_1.default.createElement("div", null, "Loading canister..."), authenticatingComponent = react_1.default.createElement("div", null, "Authenticating..."), ...restConfig }) => {
|
|
87
75
|
if (!canisterId) {
|
|
88
76
|
throw new Error("canisterId is required");
|
|
89
77
|
}
|
|
90
|
-
const config = react_1.default.useMemo(() => (
|
|
91
|
-
|
|
78
|
+
const config = react_1.default.useMemo(() => ({
|
|
79
|
+
...defaultConfig,
|
|
80
|
+
...restConfig,
|
|
81
|
+
}), [defaultConfig, restConfig]);
|
|
82
|
+
const { fetchError, isAuthenticating: authenticating, initializeActor, hooks, } = (0, useActor_1.useActor)({
|
|
83
|
+
canisterId,
|
|
84
|
+
...config,
|
|
85
|
+
});
|
|
92
86
|
const useInitializeActor = react_1.default.useCallback(() => {
|
|
93
87
|
return initializeActor;
|
|
94
88
|
}, [initializeActor]);
|
|
95
89
|
const ActorChildren = ({ useActorState }) => {
|
|
96
|
-
const {
|
|
97
|
-
return
|
|
90
|
+
const { isInitializing, isInitialized, error } = useActorState();
|
|
91
|
+
return isInitializing
|
|
98
92
|
? loadingComponent
|
|
99
|
-
:
|
|
93
|
+
: isInitialized
|
|
100
94
|
? children
|
|
101
95
|
: error
|
|
102
96
|
? errorComponent(error.message)
|
|
103
97
|
: null;
|
|
104
98
|
};
|
|
105
|
-
return (react_1.default.createElement(ActorContext.Provider, { value:
|
|
99
|
+
return (react_1.default.createElement(ActorContext.Provider, { value: { ...hooks, useInitializeActor } },
|
|
106
100
|
fetchingComponent,
|
|
107
101
|
hooks === null ? (fetchError ? (errorComponent(fetchError)) : authenticating ? (authenticatingComponent) : (loadingComponent)) : (react_1.default.createElement(ActorChildren, { useActorState: hooks.useActorState }, children))));
|
|
108
102
|
};
|
|
@@ -116,7 +110,10 @@ function createActorContext(contextConfig = {}) {
|
|
|
116
110
|
});
|
|
117
111
|
return (react_1.default.createElement(ActorContext.Provider, { value: hooks }, children));
|
|
118
112
|
};
|
|
119
|
-
return
|
|
113
|
+
return {
|
|
114
|
+
ActorProvider,
|
|
120
115
|
ActorHookProvider,
|
|
121
|
-
ActorManagerProvider
|
|
116
|
+
ActorManagerProvider,
|
|
117
|
+
...(0, extractActorContext_1.extractActorContext)(ActorContext),
|
|
118
|
+
};
|
|
122
119
|
}
|
|
@@ -7,15 +7,15 @@ import type { BaseActor, FunctionName, UseMethodParameters, UseMethodReturnType
|
|
|
7
7
|
* @example
|
|
8
8
|
* ```tsx
|
|
9
9
|
* function MethodCallComponent() {
|
|
10
|
-
* const { call, data,
|
|
10
|
+
* const { call, data, isLoading } = useMethod({
|
|
11
11
|
* functionName: 'updateUserProfile',
|
|
12
12
|
* args: ['123', { name: 'John Doe' }],
|
|
13
|
-
* onLoading: (
|
|
13
|
+
* onLoading: (isLoading) => console.log('Loading:', isLoading),
|
|
14
14
|
* onError: (error) => console.error('Error:', error),
|
|
15
15
|
* onSuccess: (data) => console.log('Success:', data),
|
|
16
16
|
* });
|
|
17
17
|
*
|
|
18
|
-
* if (
|
|
18
|
+
* if (isLoading) return <p>Updating profile...</p>;
|
|
19
19
|
*
|
|
20
20
|
* return (
|
|
21
21
|
* <div>
|
|
@@ -10,15 +10,15 @@ const __1 = require("..");
|
|
|
10
10
|
* @example
|
|
11
11
|
* ```tsx
|
|
12
12
|
* function MethodCallComponent() {
|
|
13
|
-
* const { call, data,
|
|
13
|
+
* const { call, data, isLoading } = useMethod({
|
|
14
14
|
* functionName: 'updateUserProfile',
|
|
15
15
|
* args: ['123', { name: 'John Doe' }],
|
|
16
|
-
* onLoading: (
|
|
16
|
+
* onLoading: (isLoading) => console.log('Loading:', isLoading),
|
|
17
17
|
* onError: (error) => console.error('Error:', error),
|
|
18
18
|
* onSuccess: (data) => console.log('Success:', data),
|
|
19
19
|
* });
|
|
20
20
|
*
|
|
21
|
-
* if (
|
|
21
|
+
* if (isLoading) return <p>Updating profile...</p>;
|
|
22
22
|
*
|
|
23
23
|
* return (
|
|
24
24
|
* <div>
|
|
@@ -7,14 +7,14 @@ import type { BaseActor, FunctionName, UseQueryCallParameters, UseQueryCallRetur
|
|
|
7
7
|
* @example
|
|
8
8
|
* ```tsx
|
|
9
9
|
* function QueryCallComponent() {
|
|
10
|
-
* const { call, data,
|
|
10
|
+
* const { call, data, isLoading } = useQueryCall({
|
|
11
11
|
* functionName: 'getUserProfile',
|
|
12
12
|
* args: ['123'],
|
|
13
13
|
* refetchOnMount: true,
|
|
14
14
|
* refetchInterval: 5000, // refetch every 5 seconds
|
|
15
15
|
* });
|
|
16
16
|
*
|
|
17
|
-
* if (
|
|
17
|
+
* if (isLoading) return <p>isLoading profile...</p>;
|
|
18
18
|
*
|
|
19
19
|
* return (
|
|
20
20
|
* <div>
|
|
@@ -10,14 +10,14 @@ const __1 = require("..");
|
|
|
10
10
|
* @example
|
|
11
11
|
* ```tsx
|
|
12
12
|
* function QueryCallComponent() {
|
|
13
|
-
* const { call, data,
|
|
13
|
+
* const { call, data, isLoading } = useQueryCall({
|
|
14
14
|
* functionName: 'getUserProfile',
|
|
15
15
|
* args: ['123'],
|
|
16
16
|
* refetchOnMount: true,
|
|
17
17
|
* refetchInterval: 5000, // refetch every 5 seconds
|
|
18
18
|
* });
|
|
19
19
|
*
|
|
20
|
-
* if (
|
|
20
|
+
* if (isLoading) return <p>isLoading profile...</p>;
|
|
21
21
|
*
|
|
22
22
|
* return (
|
|
23
23
|
* <div>
|
|
@@ -7,15 +7,15 @@ import type { BaseActor, FunctionName, UseUpdateCallParameters, UseUpdateCallRet
|
|
|
7
7
|
* @example
|
|
8
8
|
* ```tsx
|
|
9
9
|
* function UpdateCallComponent() {
|
|
10
|
-
* const { call, data,
|
|
10
|
+
* const { call, data, isLoading } = useUpdateCall({
|
|
11
11
|
* functionName: 'updateUserProfile',
|
|
12
12
|
* args: ['123', { name: 'John Doe' }],
|
|
13
|
-
* onLoading: (
|
|
13
|
+
* onLoading: (isLoading) => console.log('Loading:', isLoading),
|
|
14
14
|
* onError: (error) => console.error('Error:', error),
|
|
15
15
|
* onSuccess: (data) => console.log('Success:', data),
|
|
16
16
|
* });
|
|
17
17
|
*
|
|
18
|
-
* if (
|
|
18
|
+
* if (isLoading) return <p>Updating profile...</p>;
|
|
19
19
|
*
|
|
20
20
|
* return (
|
|
21
21
|
* <div>
|
|
@@ -10,15 +10,15 @@ const __1 = require("..");
|
|
|
10
10
|
* @example
|
|
11
11
|
* ```tsx
|
|
12
12
|
* function UpdateCallComponent() {
|
|
13
|
-
* const { call, data,
|
|
13
|
+
* const { call, data, isLoading } = useUpdateCall({
|
|
14
14
|
* functionName: 'updateUserProfile',
|
|
15
15
|
* args: ['123', { name: 'John Doe' }],
|
|
16
|
-
* onLoading: (
|
|
16
|
+
* onLoading: (isLoading) => console.log('Loading:', isLoading),
|
|
17
17
|
* onError: (error) => console.error('Error:', error),
|
|
18
18
|
* onSuccess: (data) => console.log('Success:', data),
|
|
19
19
|
* });
|
|
20
20
|
*
|
|
21
|
-
* if (
|
|
21
|
+
* if (isLoading) return <p>Updating profile...</p>;
|
|
22
22
|
*
|
|
23
23
|
* return (
|
|
24
24
|
* <div>
|
|
@@ -5,4 +5,4 @@ import type { FunctionName, BaseActor } from "../../../types";
|
|
|
5
5
|
* @param functionName The name of the actor method to visit.
|
|
6
6
|
* @returns The visit service function for the specified method.
|
|
7
7
|
*/
|
|
8
|
-
export declare function useVisitMethod<A = BaseActor>(functionName: FunctionName<A>): <V extends import("@dfinity/candid/lib/
|
|
8
|
+
export declare function useVisitMethod<A = BaseActor>(functionName: FunctionName<A>): <V extends import("@dfinity/candid/lib/esm/idl").Visitor<unknown, unknown>>(extractorClass: V, data: import("@ic-reactor/core/dist/classes/actor/types").VisitorType<V>["data"]) => ReturnType<V["visitFunc"]>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function createAdapterContext(config?:
|
|
1
|
+
import type { CreateCandidAdapterContextParameters, CreateCandidAdapterContextReturnType } from "./types";
|
|
2
|
+
export declare function createAdapterContext(config?: CreateCandidAdapterContextParameters): CreateCandidAdapterContextReturnType;
|
|
@@ -1,24 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
@@ -28,7 +8,7 @@ const react_1 = __importDefault(require("react"));
|
|
|
28
8
|
const agent_1 = require("../agent");
|
|
29
9
|
const core_1 = require("@ic-reactor/core");
|
|
30
10
|
function createAdapterContext(config = {}) {
|
|
31
|
-
const { withParser: _withParser, didjsCanisterId: _didjsCanisterId
|
|
11
|
+
const { withParser: _withParser, didjsCanisterId: _didjsCanisterId, ...defaultConfig } = config;
|
|
32
12
|
const CandidAdapterContext = react_1.default.createContext(null);
|
|
33
13
|
const useCandidAdapter = () => {
|
|
34
14
|
const context = react_1.default.useContext(CandidAdapterContext);
|
|
@@ -40,6 +20,7 @@ function createAdapterContext(config = {}) {
|
|
|
40
20
|
const useCandidEvaluation = () => {
|
|
41
21
|
const [state, setState] = react_1.default.useState({
|
|
42
22
|
fetching: true,
|
|
23
|
+
isFetching: true,
|
|
43
24
|
fetchError: null,
|
|
44
25
|
});
|
|
45
26
|
const candidAdapter = useCandidAdapter();
|
|
@@ -47,6 +28,7 @@ function createAdapterContext(config = {}) {
|
|
|
47
28
|
setState({
|
|
48
29
|
fetchError: null,
|
|
49
30
|
fetching: false,
|
|
31
|
+
isFetching: false,
|
|
50
32
|
});
|
|
51
33
|
try {
|
|
52
34
|
return candidAdapter.validateIDL(candidString);
|
|
@@ -55,22 +37,29 @@ function createAdapterContext(config = {}) {
|
|
|
55
37
|
setState({
|
|
56
38
|
fetchError: `Error validating Candid definition, ${err}`,
|
|
57
39
|
fetching: false,
|
|
40
|
+
isFetching: false,
|
|
58
41
|
});
|
|
42
|
+
return false;
|
|
59
43
|
}
|
|
60
44
|
}, []);
|
|
61
|
-
const
|
|
45
|
+
const isCandidValid = react_1.default.useCallback((candidString) => {
|
|
46
|
+
return validateCandid(candidString) !== false;
|
|
47
|
+
}, [validateCandid]);
|
|
48
|
+
const evaluateCandid = react_1.default.useCallback(async (candidString) => {
|
|
62
49
|
setState({
|
|
63
50
|
fetchError: null,
|
|
64
51
|
fetching: true,
|
|
52
|
+
isFetching: true,
|
|
65
53
|
});
|
|
66
54
|
try {
|
|
67
|
-
const definition =
|
|
68
|
-
if (typeof
|
|
55
|
+
const definition = await candidAdapter.evaluateCandidDefinition(candidString);
|
|
56
|
+
if (typeof definition?.idlFactory !== "function") {
|
|
69
57
|
throw new Error("No Function found in Candid definition!");
|
|
70
58
|
}
|
|
71
59
|
setState({
|
|
72
60
|
fetchError: null,
|
|
73
61
|
fetching: false,
|
|
62
|
+
isFetching: false,
|
|
74
63
|
});
|
|
75
64
|
return definition.idlFactory;
|
|
76
65
|
}
|
|
@@ -78,17 +67,21 @@ function createAdapterContext(config = {}) {
|
|
|
78
67
|
setState({
|
|
79
68
|
fetchError: `Error evaluating Candid definition, ${err}`,
|
|
80
69
|
fetching: false,
|
|
70
|
+
isFetching: false,
|
|
81
71
|
});
|
|
72
|
+
return undefined;
|
|
82
73
|
}
|
|
83
|
-
}
|
|
84
|
-
return
|
|
74
|
+
}, []);
|
|
75
|
+
return { evaluateCandid, isCandidValid, validateCandid, ...state };
|
|
85
76
|
};
|
|
86
|
-
const CandidAdapterProvider = (
|
|
87
|
-
|
|
88
|
-
|
|
77
|
+
const CandidAdapterProvider = ({ children, withParser = _withParser, loadingComponent = react_1.default.createElement("div", null, "Loading Parser..."), didjsCanisterId = _didjsCanisterId, ...restConfig }) => {
|
|
78
|
+
const config = react_1.default.useMemo(() => ({
|
|
79
|
+
...defaultConfig,
|
|
80
|
+
...restConfig,
|
|
81
|
+
}), [defaultConfig, restConfig]);
|
|
89
82
|
const [initalized, setInitialized] = react_1.default.useState(false);
|
|
90
83
|
const agentManager = (0, agent_1.useAgentManager)();
|
|
91
|
-
const candidAdapter = react_1.default.useMemo(() => (0, core_1.createCandidAdapter)(
|
|
84
|
+
const candidAdapter = react_1.default.useMemo(() => (0, core_1.createCandidAdapter)({ agentManager, didjsCanisterId, ...config }), [didjsCanisterId, agentManager]);
|
|
92
85
|
react_1.default.useEffect(() => {
|
|
93
86
|
if (withParser) {
|
|
94
87
|
candidAdapter.initializeParser().then(() => setInitialized(true));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @ignore */
|
|
2
2
|
export declare const AdapterHooks: import("./types").CreateCandidAdapterContextReturnType;
|
|
3
|
-
export declare const CandidAdapterContext: import("react").Context<import("
|
|
3
|
+
export declare const CandidAdapterContext: import("react").Context<import("@ic-reactor/core/dist/classes").CandidAdapter | null>;
|
|
4
4
|
export * from "./provider";
|
|
5
5
|
export * from "./hooks/useCandidAdapter";
|
|
6
6
|
export * from "./hooks/useCandidEvaluation";
|
|
@@ -1,20 +1,47 @@
|
|
|
1
1
|
import type { PropsWithChildren } from "react";
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
}
|
|
2
|
+
import type { IDL } from "@dfinity/candid";
|
|
3
|
+
import { CandidAdapter } from "@ic-reactor/core/dist/classes";
|
|
4
|
+
import { CandidAdapterParameters } from "../../types";
|
|
5
|
+
export type CandidAdapterContextType = CandidAdapter;
|
|
7
6
|
export interface CandidAdapterProviderProps extends PropsWithChildren, CandidAdapterParameters {
|
|
8
7
|
withParser?: boolean;
|
|
9
8
|
loadingComponent?: React.ReactNode;
|
|
10
9
|
}
|
|
11
|
-
export interface
|
|
10
|
+
export interface CreateCandidAdapterContextParameters extends CandidAdapterParameters {
|
|
12
11
|
withParser?: boolean;
|
|
13
12
|
}
|
|
14
13
|
export interface UseCandidEvaluationReturnType {
|
|
14
|
+
/**
|
|
15
|
+
* The error message encountered during the fetch operation, or `null` if no error occurred.
|
|
16
|
+
*/
|
|
15
17
|
fetchError: string | null;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `isFetching` instead.
|
|
20
|
+
* Indicates whether a fetch operation is currently in progress.
|
|
21
|
+
*/
|
|
16
22
|
fetching: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Indicates whether a fetch operation is currently in progress.
|
|
25
|
+
*/
|
|
26
|
+
isFetching: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use `isCandidValid` instead.
|
|
29
|
+
* Validates the provided Candid interface definition string.
|
|
30
|
+
* @param candidString - The Candid definition to validate.
|
|
31
|
+
* @returns `true` if the string is valid, `false` otherwise.
|
|
32
|
+
*/
|
|
17
33
|
validateCandid: (candidString: string) => boolean | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Validates the provided Candid interface definition string.
|
|
36
|
+
* @param candidString - The Candid definition to validate.
|
|
37
|
+
* @returns `true` if valid, `false` otherwise.
|
|
38
|
+
*/
|
|
39
|
+
isCandidValid: (candidString: string) => boolean | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Evaluates the provided Candid interface definition string.
|
|
42
|
+
* @param candidString - The Candid definition to evaluate.
|
|
43
|
+
* @returns A promise resolving to the corresponding InterfaceFactory if the evaluation succeeds, otherwise `undefined`.
|
|
44
|
+
*/
|
|
18
45
|
evaluateCandid: (candidString: string) => Promise<IDL.InterfaceFactory | undefined>;
|
|
19
46
|
}
|
|
20
47
|
export interface CreateCandidAdapterContextReturnType {
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
@@ -93,19 +82,23 @@ const extractAgentContext_1 = require("../../helpers/extractAgentContext");
|
|
|
93
82
|
* with the Internet Computer blockchain.
|
|
94
83
|
*/
|
|
95
84
|
function createAgentContext(config = {}) {
|
|
96
|
-
const { disableAuthenticateOnMount: defaultDisable
|
|
85
|
+
const { disableAuthenticateOnMount: defaultDisable, ...contextOptions } = config;
|
|
97
86
|
const AgentContext = react_1.default.createContext(null);
|
|
98
|
-
const AgentProvider = (
|
|
99
|
-
var { children, agentManager: mybeAgentManager, disableAuthenticateOnMount = defaultDisable !== null && defaultDisable !== void 0 ? defaultDisable : false } = _a, options = __rest(_a, ["children", "agentManager", "disableAuthenticateOnMount"]);
|
|
87
|
+
const AgentProvider = ({ children, agentManager: mybeAgentManager, disableAuthenticateOnMount = defaultDisable ?? false, ...options }) => {
|
|
100
88
|
const hooks = react_1.default.useMemo(() => {
|
|
101
|
-
const agentManager = mybeAgentManager
|
|
89
|
+
const agentManager = mybeAgentManager ??
|
|
90
|
+
(0, core_1.createAgentManager)({ ...options, ...contextOptions });
|
|
102
91
|
if (!disableAuthenticateOnMount) {
|
|
103
92
|
agentManager.authenticate();
|
|
104
93
|
}
|
|
105
|
-
return
|
|
94
|
+
return {
|
|
95
|
+
...(0, agentHooks_1.agentHooks)(agentManager),
|
|
96
|
+
...(0, authHooks_1.authHooks)(agentManager),
|
|
97
|
+
agentManager,
|
|
98
|
+
};
|
|
106
99
|
}, []);
|
|
107
100
|
return (react_1.default.createElement(AgentContext.Provider, { value: hooks }, children));
|
|
108
101
|
};
|
|
109
102
|
AgentProvider.displayName = "AgentProvider";
|
|
110
|
-
return
|
|
103
|
+
return { AgentContext, AgentProvider, ...(0, extractAgentContext_1.extractAgentContext)(AgentContext) };
|
|
111
104
|
}
|
package/dist/createReactor.js
CHANGED
|
@@ -58,7 +58,12 @@ const createReactor = (config) => {
|
|
|
58
58
|
const getAgent = () => {
|
|
59
59
|
return actorManager.agentManager.getAgent();
|
|
60
60
|
};
|
|
61
|
-
return
|
|
62
|
-
|
|
61
|
+
return {
|
|
62
|
+
getAgent,
|
|
63
|
+
getVisitFunction,
|
|
64
|
+
...(0, helpers_1.actorHooks)(actorManager),
|
|
65
|
+
...(0, helpers_1.authHooks)(actorManager.agentManager),
|
|
66
|
+
...(0, helpers_1.agentHooks)(actorManager.agentManager),
|
|
67
|
+
};
|
|
63
68
|
};
|
|
64
69
|
exports.createReactor = createReactor;
|