@ic-reactor/react 0.5.2 → 0.5.4
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.js +2 -2
- package/dist/hooks/actor.d.ts +1 -1
- package/dist/hooks/actor.js +3 -3
- package/dist/index.js +13 -3
- package/dist/types.d.ts +10 -8
- package/package.json +3 -3
package/dist/context/actor.js
CHANGED
|
@@ -58,7 +58,7 @@ const useActor = () => {
|
|
|
58
58
|
};
|
|
59
59
|
exports.useActor = useActor;
|
|
60
60
|
const ActorProvider = (_a) => {
|
|
61
|
-
var { children, canisterId, agentContext, loadingComponent = react_1.default.createElement("div", null, "Loading..."),
|
|
61
|
+
var { children, canisterId, agentContext, loadingComponent = react_1.default.createElement("div", null, "Loading..."), withServiceFields = false } = _a, config = __rest(_a, ["children", "canisterId", "agentContext", "loadingComponent", "withServiceFields"]);
|
|
62
62
|
const agentManager = (0, agent_1.useAgentManager)(agentContext);
|
|
63
63
|
const [didJs, setDidJS] = (0, react_1.useState)();
|
|
64
64
|
const [fetching, setFetching] = (0, react_1.useState)(false);
|
|
@@ -112,7 +112,7 @@ const ActorProvider = (_a) => {
|
|
|
112
112
|
agentManager,
|
|
113
113
|
canisterId,
|
|
114
114
|
withDevtools: config.withDevtools,
|
|
115
|
-
|
|
115
|
+
withServiceFields: withServiceFields,
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
catch (err) {
|
package/dist/hooks/actor.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ActorManager } from "@ic-reactor/store";
|
|
2
2
|
import type { ActorHooks } from "../types";
|
|
3
|
-
export declare const getActorHooks: <A extends unknown>({ initialize, serviceFields,
|
|
3
|
+
export declare const getActorHooks: <A extends unknown>({ initialize, serviceFields, withServiceFields, canisterId, actorStore, callMethod, }: ActorManager<A>) => ActorHooks<A, boolean>;
|
package/dist/hooks/actor.js
CHANGED
|
@@ -23,14 +23,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
exports.getActorHooks = void 0;
|
|
24
24
|
const react_1 = require("react");
|
|
25
25
|
const zustand_1 = require("zustand");
|
|
26
|
-
const getActorHooks = ({ initialize, serviceFields,
|
|
26
|
+
const getActorHooks = ({ initialize, serviceFields, withServiceFields, canisterId, actorStore, callMethod, }) => {
|
|
27
27
|
const useActorStore = () => {
|
|
28
28
|
const actorState = (0, zustand_1.useStore)(actorStore, (state) => state);
|
|
29
29
|
return Object.assign(Object.assign({}, actorState), { canisterId });
|
|
30
30
|
};
|
|
31
31
|
const useServiceFields = () => {
|
|
32
|
-
if (!
|
|
33
|
-
throw new Error("Service fields not initialized. Pass `
|
|
32
|
+
if (!withServiceFields || !serviceFields) {
|
|
33
|
+
throw new Error("Service fields not initialized. Pass `withServiceFields` to initialize service fields.");
|
|
34
34
|
}
|
|
35
35
|
return serviceFields;
|
|
36
36
|
};
|
package/dist/index.js
CHANGED
|
@@ -33,14 +33,24 @@ __exportStar(require("@ic-reactor/store"), exports);
|
|
|
33
33
|
__exportStar(require("./context/agent"), exports);
|
|
34
34
|
__exportStar(require("./context/actor"), exports);
|
|
35
35
|
const createReActor = (_a) => {
|
|
36
|
-
var { isLocalEnv,
|
|
36
|
+
var { isLocalEnv, withServiceFields } = _a, options = __rest(_a, ["isLocalEnv", "withServiceFields"]);
|
|
37
37
|
isLocalEnv =
|
|
38
38
|
isLocalEnv ||
|
|
39
39
|
(typeof process !== "undefined" &&
|
|
40
40
|
(process.env.DFX_NETWORK === "local" ||
|
|
41
41
|
process.env.NODE_ENV === "development"));
|
|
42
42
|
const actorManager = (0, store_1.createReActorStore)(Object.assign({ isLocalEnv,
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
withServiceFields }, options));
|
|
44
|
+
const getServiceFields = () => {
|
|
45
|
+
if (!withServiceFields || !actorManager.serviceFields) {
|
|
46
|
+
throw new Error("Service fields not initialized. Pass `withServiceFields` to initialize service fields.");
|
|
47
|
+
}
|
|
48
|
+
return actorManager.serviceFields;
|
|
49
|
+
};
|
|
50
|
+
const getAgent = () => {
|
|
51
|
+
return actorManager.agentManager.getAgent();
|
|
52
|
+
};
|
|
53
|
+
return Object.assign(Object.assign({ getAgent,
|
|
54
|
+
getServiceFields }, (0, actor_1.getActorHooks)(actorManager)), (0, auth_1.getAuthHooks)(actorManager.agentManager));
|
|
45
55
|
};
|
|
46
56
|
exports.createReActor = createReActor;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { ActorState, ActorSubclass, CanisterId, CreateReActorOptions, ExtractActorMethodArgs, ExtractActorMethodReturnType, ExtractedFunction, ExtractedService, Identity, Principal, ServiceMethodType, ServiceMethodTypeAndName } from "@ic-reactor/store";
|
|
3
|
-
import { AuthHooks } from "./hooks/auth";
|
|
4
|
-
export type * from "@ic-reactor/store";
|
|
5
|
-
export type * from "@ic-reactor/store/dist/actor/types";
|
|
2
|
+
import type { ActorState, ActorSubclass, CanisterId, CreateReActorOptions, ExtractActorMethodArgs, ExtractActorMethodReturnType, ExtractedFunction, ExtractedService, HttpAgent, Identity, Principal, ServiceMethodType, ServiceMethodTypeAndName } from "@ic-reactor/store";
|
|
3
|
+
import type { AuthHooks } from "./hooks/auth";
|
|
6
4
|
export type AuthArgs = {
|
|
7
5
|
onAuthentication?: (promise: () => Promise<Identity>) => void;
|
|
8
6
|
onAuthenticationSuccess?: (identity: Identity) => void;
|
|
@@ -67,11 +65,15 @@ export interface ActorDefaultHooks<A, W extends boolean = false> {
|
|
|
67
65
|
type: T;
|
|
68
66
|
}) => T extends "query" ? ActorUseQueryReturn<A, M, W> : ActorUseUpdateReturn<A, M, W>;
|
|
69
67
|
}
|
|
68
|
+
export type GetFunctions<A> = {
|
|
69
|
+
getAgent: () => HttpAgent;
|
|
70
|
+
getServiceFields: () => ExtractedService<A>;
|
|
71
|
+
};
|
|
70
72
|
export type CreateReActor = {
|
|
71
73
|
<A extends ActorSubclass<any>>(options: CreateReActorOptions & {
|
|
72
|
-
|
|
73
|
-
}): ActorHooksWithField<A> & AuthHooks;
|
|
74
|
+
withServiceFields: true;
|
|
75
|
+
}): GetFunctions<A> & ActorHooksWithField<A> & AuthHooks;
|
|
74
76
|
<A extends ActorSubclass<any>>(options: CreateReActorOptions & {
|
|
75
|
-
|
|
76
|
-
}): ActorHooksWithoutField<A> & AuthHooks;
|
|
77
|
+
withServiceFields?: false | undefined;
|
|
78
|
+
}): GetFunctions<A> & ActorHooksWithoutField<A> & AuthHooks;
|
|
77
79
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "A React library for interacting with Dfinity actors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"node": ">=10"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ic-reactor/store": "^0.5.
|
|
38
|
+
"@ic-reactor/store": "^0.5.2",
|
|
39
39
|
"zustand-utils": "^1.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react": ">=16.8",
|
|
49
49
|
"zustand": "4.4"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "e2ec7048f2d3517cb5ffb9a9188d508cb50fe924"
|
|
52
52
|
}
|