@ic-reactor/react 0.5.1 → 0.5.3
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 +4 -4
- package/dist/index.js +2 -2
- package/dist/types.d.ts +3 -3
- 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
|
};
|
|
@@ -125,11 +125,11 @@ const getActorHooks = ({ initialize, serviceFields, withServiceField, canisterId
|
|
|
125
125
|
};
|
|
126
126
|
return {
|
|
127
127
|
initialize,
|
|
128
|
-
useMethods,
|
|
129
128
|
useQueryCall,
|
|
130
129
|
useUpdateCall,
|
|
131
130
|
useMethodCall,
|
|
132
131
|
useActorStore,
|
|
132
|
+
useMethods,
|
|
133
133
|
useMethodField,
|
|
134
134
|
useMethodFields,
|
|
135
135
|
useServiceFields,
|
package/dist/index.js
CHANGED
|
@@ -33,14 +33,14 @@ __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
|
-
|
|
43
|
+
withServiceFields }, options));
|
|
44
44
|
return Object.assign(Object.assign({}, (0, actor_1.getActorHooks)(actorManager)), (0, auth_1.getAuthHooks)(actorManager.agentManager));
|
|
45
45
|
};
|
|
46
46
|
exports.createReActor = createReActor;
|
package/dist/types.d.ts
CHANGED
|
@@ -53,13 +53,13 @@ export interface ActorFieldHooks<A> {
|
|
|
53
53
|
useServiceFields: () => ExtractedService<A>;
|
|
54
54
|
useMethodFields: () => ExtractedFunction<A>[];
|
|
55
55
|
useMethodField: (functionName: keyof A & string) => ExtractedFunction<A>;
|
|
56
|
+
useMethods: () => ServiceMethodTypeAndName<A>[];
|
|
56
57
|
}
|
|
57
58
|
export type UseActorStoreReturn<A> = ActorState<A> & {
|
|
58
59
|
canisterId: CanisterId;
|
|
59
60
|
};
|
|
60
61
|
export interface ActorDefaultHooks<A, W extends boolean = false> {
|
|
61
62
|
initialize: () => Promise<void>;
|
|
62
|
-
useMethods: () => ServiceMethodTypeAndName<A>[];
|
|
63
63
|
useActorStore: () => UseActorStoreReturn<A>;
|
|
64
64
|
useQueryCall: <M extends keyof A>(args: ActorUseQueryArgs<A, M>) => ActorUseQueryReturn<A, M, W>;
|
|
65
65
|
useUpdateCall: <M extends keyof A>(args: ActorUseUpdateArgs<A, M>) => ActorUseUpdateReturn<A, M, W>;
|
|
@@ -69,9 +69,9 @@ export interface ActorDefaultHooks<A, W extends boolean = false> {
|
|
|
69
69
|
}
|
|
70
70
|
export type CreateReActor = {
|
|
71
71
|
<A extends ActorSubclass<any>>(options: CreateReActorOptions & {
|
|
72
|
-
|
|
72
|
+
withServiceFields: true;
|
|
73
73
|
}): ActorHooksWithField<A> & AuthHooks;
|
|
74
74
|
<A extends ActorSubclass<any>>(options: CreateReActorOptions & {
|
|
75
|
-
|
|
75
|
+
withServiceFields?: false | undefined;
|
|
76
76
|
}): ActorHooksWithoutField<A> & AuthHooks;
|
|
77
77
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
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": "581df4947caeb34fcdf2b773e5f8543fdb5ceaaa"
|
|
52
52
|
}
|