@ic-reactor/react 1.12.2 → 1.13.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.
@@ -114,7 +114,7 @@ const actorHooks = (actorManager) => {
114
114
  }, [functionName]);
115
115
  };
116
116
  const useSharedCall = (_a) => {
117
- var { args = [], functionName, throwOnError = false, onError, onLoading, onSuccess } = _a, options = __rest(_a, ["args", "functionName", "throwOnError", "onError", "onLoading", "onSuccess"]);
117
+ var { args = [], functionName, throwOnError = false, onError, onLoading, onSuccess, onSuccessResult } = _a, options = __rest(_a, ["args", "functionName", "throwOnError", "onError", "onLoading", "onSuccess", "onSuccessResult"]);
118
118
  const requestKey = React.useMemo(() => (0, utils_1.generateRequestHash)(args), [args]);
119
119
  const [sharedState, setSharedState] = useMethodState(functionName, requestKey);
120
120
  const latestDataRef = React.useRef();
@@ -130,7 +130,8 @@ const actorHooks = (actorManager) => {
130
130
  const data = yield callMethodWithOptions(options)(functionName, ...(replaceArgs !== null && replaceArgs !== void 0 ? replaceArgs : args));
131
131
  latestDataRef.current = data;
132
132
  setSharedState({ data, error: undefined, loading: false });
133
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess((0, utils_1.createCompiledResult)(data));
133
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
134
+ onSuccessResult === null || onSuccessResult === void 0 ? void 0 : onSuccessResult((0, utils_1.createCompiledResult)(data));
134
135
  onLoading === null || onLoading === void 0 ? void 0 : onLoading(false);
135
136
  return data;
136
137
  }
@@ -147,7 +148,16 @@ const actorHooks = (actorManager) => {
147
148
  if (throwOnError)
148
149
  throw error;
149
150
  }
150
- }), [args, functionName, options, onError, onLoading, onSuccess, throwOnError]);
151
+ }), [
152
+ args,
153
+ functionName,
154
+ options,
155
+ onError,
156
+ onLoading,
157
+ onSuccess,
158
+ onSuccessResult,
159
+ throwOnError,
160
+ ]);
151
161
  const compileResult = () => {
152
162
  return (0, utils_1.createCompiledResult)(latestDataRef.current || (sharedState === null || sharedState === void 0 ? void 0 : sharedState.data));
153
163
  };
@@ -161,7 +171,7 @@ const actorHooks = (actorManager) => {
161
171
  const _b = useSharedCall(rest), { call, requestKey } = _b, state = __rest(_b, ["call", "requestKey"]);
162
172
  const intervalId = React.useRef();
163
173
  React.useEffect(() => {
164
- var _a;
174
+ var _a, _b;
165
175
  if (refetchInterval) {
166
176
  intervalId.current = setInterval(call, refetchInterval);
167
177
  }
@@ -169,7 +179,8 @@ const actorHooks = (actorManager) => {
169
179
  call();
170
180
  }
171
181
  else if (refetchOnMount && state.data !== undefined) {
172
- (_a = rest.onSuccess) === null || _a === void 0 ? void 0 : _a.call(rest, (0, utils_1.createCompiledResult)(state.data));
182
+ (_a = rest.onSuccess) === null || _a === void 0 ? void 0 : _a.call(rest, state.data);
183
+ (_b = rest.onSuccessResult) === null || _b === void 0 ? void 0 : _b.call(rest, (0, utils_1.createCompiledResult)(state.data));
173
184
  }
174
185
  return () => clearInterval(intervalId.current);
175
186
  }, [refetchInterval, refetchOnMount, requestKey]);
@@ -52,7 +52,8 @@ export interface UseSharedCallParameters<A, M extends FunctionName<A>> extends C
52
52
  args?: ActorMethodParameters<A[M]>;
53
53
  onLoading?: (loading: boolean) => void;
54
54
  onError?: (error: Error | undefined) => void;
55
- onSuccess?: (data: CompiledResult<ActorMethodReturnType<A[M]>>) => void;
55
+ onSuccess?: (data: ActorMethodReturnType<A[M]>) => void;
56
+ onSuccessResult?: (result: CompiledResult<ActorMethodReturnType<A[M]>>) => void;
56
57
  throwOnError?: boolean;
57
58
  compileResult?: boolean;
58
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/react",
3
- "version": "1.12.2",
3
+ "version": "1.13.0",
4
4
  "description": "A React library for interacting with Internet Computer canisters",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -47,5 +47,5 @@
47
47
  "react": ">=16.8",
48
48
  "zustand": "4.5"
49
49
  },
50
- "gitHead": "83eaedfd96a494e188b0b35366761800ea3be186"
50
+ "gitHead": "2336c03931dda3c24bdb3c13946ec63a9b8b0e99"
51
51
  }