@ic-reactor/react 0.1.2 → 0.2.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/README.md CHANGED
@@ -87,7 +87,3 @@ Contributions to `@ic-reactor/react` are welcome! Please read our [contributing
87
87
  ## License
88
88
 
89
89
  `@ic-reactor/react` is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
90
-
91
- ---
92
-
93
- This README provides a foundational overview of your package. You should expand it with more detailed documentation, examples, and links to additional resources or documentation as needed. Replace placeholders with actual information and links relevant to your project.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,15 @@
1
- import type { HttpAgent } from "@dfinity/agent";
2
1
  import { AuthClientLoginOptions } from "@dfinity/auth-client";
3
2
  import type { ActorSubclass, ReActorAuthStore, ReActorOptions } from "@ic-reactor/store";
4
3
  export type ReActorContextType<A = ActorSubclass<any>> = ReActorAuthStore<A>;
5
- export declare const createReActor: <A extends unknown>(actorInitializer: (agent: HttpAgent) => A, options?: ReActorOptions) => {
6
- useActorStore: () => import("@ic-reactor/store").ReActorActorState<A>;
4
+ export declare const createReActor: <A extends unknown>(options: ReActorOptions) => {
5
+ useActorStore: () => {
6
+ initialize: (agentOptions?: import("@dfinity/agent").HttpAgentOptions | undefined, identity?: import("@ic-reactor/store").Identity | undefined) => void;
7
+ actor: A | null;
8
+ initialized: boolean;
9
+ initializing: boolean;
10
+ error: Error | undefined;
11
+ methodState: import("@ic-reactor/store").ReActorMethodStates<A>;
12
+ };
7
13
  useAuthStore: () => import("@ic-reactor/store").ReActorAuthState<A>;
8
14
  useQueryCall: <M extends keyof A>({ autoRefresh, refreshInterval, disableInitialCall, ...rest }: import("./types").ReActorUseQueryArgs<A, M>) => {
9
15
  data: import("@ic-reactor/store").ExtractReActorMethodReturnType<A[M]> | undefined;
@@ -21,7 +27,7 @@ export declare const createReActor: <A extends unknown>(actorInitializer: (agent
21
27
  authClient: import("@dfinity/auth-client").AuthClient | null;
22
28
  authenticated: boolean;
23
29
  authenticating: boolean;
24
- identity: import("@dfinity/agent").Identity | null;
30
+ identity: import("@ic-reactor/store").Identity | null;
25
31
  login: (options?: AuthClientLoginOptions) => Promise<void>;
26
32
  logout: (options?: {
27
33
  returnTo?: string;
package/dist/index.js CHANGED
@@ -14,18 +14,17 @@ const store_1 = require("@ic-reactor/store");
14
14
  const react_1 = require("react");
15
15
  const zustand_1 = require("zustand");
16
16
  const hooks_1 = require("./hooks");
17
- const defaultCreateReActorOptions = {
18
- initializeOnMount: true,
19
- host: (process === null || process === void 0 ? void 0 : process.env.NODE_ENV) === "production" || (process === null || process === void 0 ? void 0 : process.env.DFX_NETWORK) === "ic"
20
- ? "https://icp-api.io"
21
- : "http://localhost:4943",
22
- };
23
- const createReActor = (actorInitializer, options = {}) => {
24
- const optionsWithDefaults = Object.assign(Object.assign({}, defaultCreateReActorOptions), options);
25
- const { callMethod, authenticate, authStore, actorStore } = (0, store_1.createReActorStore)((agent) => actorInitializer(agent), optionsWithDefaults);
17
+ const isLocal = (process === null || process === void 0 ? void 0 : process.env.NODE_ENV) === "development" ||
18
+ (process === null || process === void 0 ? void 0 : process.env.DFX_NETWORK) === "local";
19
+ const createReActor = (options) => {
20
+ const { callMethod, unsubscribe, initialize, authenticate, authStore, actorStore, } = (0, store_1.createReActorStore)(Object.assign(Object.assign({ isLocal }, options), { initializeOnMount: false }));
26
21
  const useActorStore = () => {
27
22
  const actorState = (0, zustand_1.useStore)(actorStore, (state) => state);
28
- return actorState;
23
+ (0, react_1.useEffect)(() => {
24
+ initialize();
25
+ return unsubscribe;
26
+ }, []);
27
+ return Object.assign(Object.assign({}, actorState), { initialize });
29
28
  };
30
29
  const useAuthStore = () => {
31
30
  const authState = (0, zustand_1.useStore)(authStore, (state) => state);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/react",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "A React library for interacting with Dfinity actors",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "@dfinity/candid": "0.20",
41
41
  "@dfinity/identity": "^0.20",
42
42
  "@dfinity/principal": "^0.20",
43
- "@ic-reactor/store": "^0.1.2",
43
+ "@ic-reactor/store": "^0.2.0",
44
44
  "zustand": "4.4",
45
45
  "zustand-utils": "^1.3"
46
46
  },
@@ -48,5 +48,5 @@
48
48
  "@peculiar/webcrypto": "1.4",
49
49
  "react": ">=16.8"
50
50
  },
51
- "gitHead": "6710ddba717421913c2a9765e7c626fea204e2e7"
51
+ "gitHead": "8499f295b9e20d1dc12bd4f0a33927bfce54c23a"
52
52
  }