@ic-reactor/core 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +31 -16
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -27,24 +27,21 @@ yarn add @ic-reactor/core
27
27
  To get started with ReActor, you'll need to initialize it with your actor configurations. Here's a basic example:
28
28
 
29
29
  ```javascript
30
- import createReActor from "@ic-reactor/core"
31
-
32
- const { store, actions, initializeActor, queryCall, updateCall } =
33
- createReActor(
34
- (agent) =>
35
- createActor("bd3sg-teaaa-aaaaa-qaaba-cai", {
36
- agent,
37
- }),
38
- {
39
- host: "https://localhost:4943",
40
- }
41
- )
30
+ import { createReActor } from "@ic-reactor/core"
31
+
32
+ const { actorStore, authStore, queryCall, updateCall } = createReActor(
33
+ (agent) => createActor("bd3sg-teaaa-aaaaa-qaaba-cai", { agent }),
34
+ {
35
+ host: "https://localhost:4943",
36
+ initializeOnMount: true,
37
+ }
38
+ )
42
39
  ```
43
40
 
44
41
  ### Querying Data
45
42
 
46
43
  ```javascript
47
- const { recall, subscribe, getState } = queryCall({
44
+ const { recall, subscribe, getState, initialData, intervalId } = queryCall({
48
45
  functionName: "yourFunctionName",
49
46
  args: ["arg1", "arg2"],
50
47
  autoRefresh: true,
@@ -60,12 +57,22 @@ const unsubscribe = subscribe((newState) => {
60
57
  recall().then((data) => {
61
58
  // Handle initial data
62
59
  })
60
+
61
+ // Get initial data
62
+ initialData.then((data) => {
63
+ // Handle initial data
64
+ })
65
+
66
+ // Clear interval if autoRefresh is enabled
67
+ if (intervalId) {
68
+ clearInterval(intervalId)
69
+ }
63
70
  ```
64
71
 
65
72
  ### Updating Data
66
73
 
67
74
  ```javascript
68
- const { call } = updateCall({
75
+ const { call, getState, subscribe } = updateCall({
69
76
  functionName: "yourUpdateFunction",
70
77
  args: ["arg1", "arg2"],
71
78
  })
@@ -73,12 +80,20 @@ const { call } = updateCall({
73
80
  call().then((result) => {
74
81
  // Handle result
75
82
  })
83
+
84
+ // Get state
85
+ const state = getState()
86
+
87
+ // Subscribe to changes
88
+ const unsubscribe = subscribe((newState) => {
89
+ // Handle new state
90
+ })
76
91
  ```
77
92
 
78
93
  ## API Reference
79
94
 
80
- - `queryCall`: Fetches and subscribes to data from an actor method.
81
- - `updateCall`: Updates data and handles state changes for an actor method.
95
+ - `queryCall`: Fetches and subscribes to data from an actor method. Returns an object containing methods for recalling data, subscribing to changes, getting the current state, and the initial data promise.
96
+ - `updateCall`: Updates data and handles state changes for an actor method. Returns an object containing methods for calling the update function, subscribing to changes, and getting the current state.
82
97
  - `getState`: Retrieves the current state based on the request hash.
83
98
  - `subscribe`: Allows subscription to state changes.
84
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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,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.0",
43
+ "@ic-reactor/store": "^0.1.2",
44
44
  "zustand": "4.4"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@peculiar/webcrypto": "1.4"
48
48
  },
49
- "gitHead": "238573fa8659f047268202ad94865b3344949847"
49
+ "gitHead": "6710ddba717421913c2a9765e7c626fea204e2e7"
50
50
  }