@ic-reactor/core 0.1.2 → 0.2.1
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/index.d.ts +3 -7
- package/dist/index.js +5 -9
- package/dist/types.d.ts +2 -2
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ActorSubclass, ReActorAuthStore } from "@ic-reactor/store";
|
|
1
|
+
import type { ActorSubclass, ReActorAuthStore, ReActorOptions } from "@ic-reactor/store";
|
|
3
2
|
import { ReActorQuery, ReActorUpdate } from "./types";
|
|
4
3
|
export type ReActorContextType<A = ActorSubclass<any>> = ReActorAuthStore<A>;
|
|
5
|
-
export
|
|
6
|
-
initializeOnMount?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare const createReActor: <A extends unknown>(actorInitializer: (agent: HttpAgent) => A, options?: CreateReActorOptions) => {
|
|
4
|
+
export declare const createReActor: <A extends unknown>(options: ReActorOptions) => {
|
|
9
5
|
unsubscribe: () => void;
|
|
10
|
-
initialize: (agentOptions?: HttpAgentOptions | undefined, identity?: import("@
|
|
6
|
+
initialize: (agentOptions?: import("@dfinity/agent").HttpAgentOptions | undefined, identity?: import("@ic-reactor/store").Identity | undefined) => void;
|
|
11
7
|
authenticate: () => Promise<void>;
|
|
12
8
|
actorStore: import("@ic-reactor/store").ReActorActorStore<A>;
|
|
13
9
|
authStore: ReActorAuthStore<A>;
|
package/dist/index.js
CHANGED
|
@@ -22,12 +22,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.createReActor = void 0;
|
|
24
24
|
const store_1 = require("@ic-reactor/store");
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
const createReActor = (actorInitializer, options = {}) => {
|
|
29
|
-
const optionsWithDefaults = Object.assign(Object.assign({}, defaultCreateReActorOptions), options);
|
|
30
|
-
const _a = (0, store_1.createReActorStore)((agent) => actorInitializer(agent), optionsWithDefaults), { callMethod, actorStore, authStore } = _a, rest = __rest(_a, ["callMethod", "actorStore", "authStore"]);
|
|
25
|
+
const createReActor = (options) => {
|
|
26
|
+
const _a = (0, store_1.createReActorStore)(options), { callMethod, actorStore, authStore } = _a, rest = __rest(_a, ["callMethod", "actorStore", "authStore"]);
|
|
31
27
|
const updateMethodState = (method, args = [], newState) => {
|
|
32
28
|
const hash = (0, store_1.generateRequestHash)(args);
|
|
33
29
|
actorStore.setState((state) => {
|
|
@@ -39,7 +35,7 @@ const createReActor = (actorInitializer, options = {}) => {
|
|
|
39
35
|
console.error(`Method ${String(method)} not found`);
|
|
40
36
|
return state;
|
|
41
37
|
}
|
|
42
|
-
const currentMethodState = state.methodState[method]
|
|
38
|
+
const currentMethodState = state.methodState[method][hash] || {
|
|
43
39
|
loading: false,
|
|
44
40
|
data: undefined,
|
|
45
41
|
error: undefined,
|
|
@@ -52,7 +48,7 @@ const createReActor = (actorInitializer, options = {}) => {
|
|
|
52
48
|
try {
|
|
53
49
|
const requestHash = updateMethodState(functionName, args);
|
|
54
50
|
const getState = (key) => {
|
|
55
|
-
const state = actorStore.getState().methodState[functionName]
|
|
51
|
+
const state = actorStore.getState().methodState[functionName][requestHash];
|
|
56
52
|
switch (key) {
|
|
57
53
|
case "data":
|
|
58
54
|
return state.data;
|
|
@@ -67,7 +63,7 @@ const createReActor = (actorInitializer, options = {}) => {
|
|
|
67
63
|
const subscribe = (callback) => {
|
|
68
64
|
const unsubscribe = actorStore.subscribe((state) => {
|
|
69
65
|
const methodState = state.methodState[functionName];
|
|
70
|
-
const methodStateHash = methodState
|
|
66
|
+
const methodStateHash = methodState[requestHash];
|
|
71
67
|
if (methodStateHash) {
|
|
72
68
|
callback(methodStateHash);
|
|
73
69
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ export type ReActorGetStateFunction<A, M extends keyof A> = {
|
|
|
4
4
|
(key: "data"): ExtractReActorMethodReturnType<A[M]> | undefined;
|
|
5
5
|
(key: "loading"): boolean;
|
|
6
6
|
(key: "error"): Error | undefined;
|
|
7
|
-
(): ReActorMethodState<A, M>[
|
|
7
|
+
(): ReActorMethodState<A, M>[string];
|
|
8
8
|
};
|
|
9
|
-
export type ReActorSubscribeFunction<A, M extends keyof A> = (callback: (state: ReActorMethodState<A, M>[
|
|
9
|
+
export type ReActorSubscribeFunction<A, M extends keyof A> = (callback: (state: ReActorMethodState<A, M>[string]) => void) => () => void;
|
|
10
10
|
export type ReActorCallFunction<A, M extends keyof A> = (replaceArgs?: ExtractReActorMethodArgs<A[M]>) => Promise<ExtractReActorMethodReturnType<A[M]> | undefined>;
|
|
11
11
|
export type ReActorQueryReturn<A, M extends keyof A> = {
|
|
12
12
|
intervalId: NodeJS.Timeout | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A React library for interacting with Dfinity actors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"test": "npx jest",
|
|
30
30
|
"start": "tsc watch",
|
|
31
|
-
"build": "npx tsc",
|
|
32
|
-
"clean": "rimraf dist"
|
|
31
|
+
"build": "npx rimraf dist && npx tsc",
|
|
32
|
+
"clean": "npx rimraf dist"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
35
|
"node": ">=10"
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"@dfinity/candid": "0.20",
|
|
41
41
|
"@dfinity/identity": "^0.20",
|
|
42
42
|
"@dfinity/principal": "^0.20",
|
|
43
|
-
"@ic-reactor/store": "^0.1
|
|
43
|
+
"@ic-reactor/store": "^0.2.1",
|
|
44
44
|
"zustand": "4.4"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@peculiar/webcrypto": "1.4"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "fcc3b98a8d2f1590a7631225eaec246c231b1815"
|
|
50
50
|
}
|