rhine-var 0.4.8 → 0.4.10

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
@@ -3,22 +3,37 @@
3
3
  # RHINE-VAR: Simplest and Powerful CRDT Library
4
4
 
5
5
  Rhine Variable — A self-synchronizing variable for collaboration.
6
- Developing collaborative applications has never been this easy.
7
6
 
8
7
 
9
8
  [English](README.md)   |   [中文](README_zh.md)
10
9
 
11
- <img src='./assets/images/example1.png' style="border-radius: 10px"/>
10
+ <img src='./assets/images/example_counter.png' style="border-radius: 10px"/>
12
11
 
13
12
  </div>
14
13
 
14
+ ```typescript jsx
15
+ const state = rhineProxy({count: 0}, 'room-0') // Create
16
+ function Counter() {
17
+ const snap = useRhine(state) // Hook for React
18
+ return <div>
19
+ <span>{snap.count}</span> // Automatic Update
20
+ <button onClick={() => state.count-- }> -1 </button> // Operate Anyway
21
+ <button onClick={() => state.count++ }> +1 </button>
22
+ </div>
23
+ }
24
+ ```
25
+
26
+ Try: [https://rv.rhineai.com/examples/counter](https://rv.rhineai.com/examples/counter)
27
+
15
28
  <br/>
16
29
 
17
- ### **Document:** [LEARN.md](assets/documents/LEARN.md)
30
+ ## Overview
31
+
32
+ **Document:** [LEARN_zh.md](assets/documents/LEARN_zh.md)
18
33
 
19
- ### **Github:** [https://github.com/RhineAI-Lab/rhine-var](https://github.com/RhineAI-Lab/rhine-var)
34
+ **Github:** [https://github.com/RhineAI-Lab/rhine-var](https://github.com/RhineAI-Lab/rhine-var)
20
35
 
21
- ### **Npm:** [https://www.npmjs.com/package/rhine-var](https://www.npmjs.com/package/rhine-var)
36
+ **Npm:** [https://www.npmjs.com/package/rhine-var](https://www.npmjs.com/package/rhine-var)
22
37
 
23
38
  <br/>
24
39
 
@@ -92,16 +107,17 @@ If you don't have `yarn`, you can install it via `npm i rhine-var`, or install `
92
107
  ```typescript jsx
93
108
  const defaultValue = {value: 0}
94
109
  const url = 'ws://localhost:6600/room-0'
95
- const count = rhineProxy(defaultValue, url)
110
+
111
+ const state = rhineProxy(defaultValue, url)
96
112
 
97
113
  function Counter() {
98
114
 
99
- const countSnap = useRhine(count)
115
+ const snap = useRhine(state)
100
116
 
101
117
  return <div>
102
- <button onClick={() => count.value-- }> - 1 </button>
103
- <span>{countSnap.value}</span>
104
- <button onClick={() => count.value++ }> + 1 </button>
118
+ <button onClick={() => state.count-- }> -1 </button>
119
+ <span>{snap.count}</span>
120
+ <button onClick={() => state.count++ }> +1 </button>
105
121
  </div>
106
122
  }
107
123
  ```
@@ -125,6 +141,8 @@ Its data structure `can be quite complex`, but `at least`, it is `an object` in
125
141
 
126
142
  A hook for use with React. It creates a snapshot of a `RhineVar Object`, and whenever someone modifies this value, the information will be `updated on everyone's screen` in real-time.
127
143
 
144
+ Note: The returned snapshot is read-only. Please do not perform any operations on it! The snapshot is only for reading data within React's XML. For all other operations (such as assignment or subscription), please operate on the original RhineVar object.
145
+
128
146
  <br/>
129
147
 
130
148
  #### [Click to view the full document: LEARN.md](assets/documents/LEARN.md)
package/README_zh.md CHANGED
@@ -2,21 +2,37 @@
2
2
 
3
3
  # 最简单且强大的多人协同框架 RHINE-VAR
4
4
 
5
- 莱茵变量 —— 会自己与他人协同的变量 &nbsp; 多人协同应用开发从未如此简单
5
+ 莱茵变量 —— 会自己与他人协同的变量 &nbsp; 多人协同应用开发从未如此简单
6
6
 
7
7
  [English](README.md) &nbsp; | &nbsp; [中文](README_zh.md)
8
8
 
9
- <img src='./assets/images/example1.png' style="border-radius: 10px; max-width: 840px"/>
9
+ <img src='./assets/images/example_counter.png' style="border-radius: 10px"/>
10
10
 
11
11
  </div>
12
12
 
13
+ ```typescript jsx
14
+ const state = rhineProxy({count: 0}, 'room-0') // Create
15
+ function Counter() {
16
+ const snap = useRhine(state) // Hook for React
17
+ return <div>
18
+ <span>{snap.count}</span> // Automatic Update
19
+ <button onClick={() => state.count-- }> -1 </button> // Operate Anyway
20
+ <button onClick={() => state.count++ }> +1 </button>
21
+ </div>
22
+ }
23
+ ```
24
+
25
+ Try: [https://rv.rhineai.com/examples/counter](https://rv.rhineai.com/examples/counter)
26
+
13
27
  <br/>
14
28
 
15
- ### **Document:** [LEARN_zh.md](assets/documents/LEARN_zh.md)
29
+ ## 简介
30
+
31
+ **Document:** [LEARN_zh.md](assets/documents/LEARN_zh.md)
16
32
 
17
- ### **Github:** [https://github.com/RhineAI-Lab/rhine-var](https://github.com/RhineAI-Lab/rhine-var)
33
+ **Github:** [https://github.com/RhineAI-Lab/rhine-var](https://github.com/RhineAI-Lab/rhine-var)
18
34
 
19
- ### **Npm:** [https://www.npmjs.com/package/rhine-var](https://www.npmjs.com/package/rhine-var)
35
+ **Npm:** [https://www.npmjs.com/package/rhine-var](https://www.npmjs.com/package/rhine-var)
20
36
 
21
37
  <br/>
22
38
 
@@ -101,17 +117,19 @@ yarn add rhine-var
101
117
  ## Usage
102
118
 
103
119
  ```typescript jsx
104
- const defaultValue = {count: 0}
105
- const state = rhineProxy(defaultValue, 'room-0')
120
+ const defaultValue = {value: 0}
121
+ const url = 'ws://localhost:6600/room-0'
122
+
123
+ const state = rhineProxy(defaultValue, url)
106
124
 
107
125
  function Counter() {
108
126
 
109
127
  const snap = useRhine(state)
110
128
 
111
129
  return <div>
112
- <button onClick={() => state.count-- }> - 1 </button>
130
+ <button onClick={() => state.count-- }> -1 </button>
113
131
  <span>{snap.count}</span>
114
- <button onClick={() => state.count++ }> + 1 </button>
132
+ <button onClick={() => state.count++ }> +1 </button>
115
133
  </div>
116
134
  }
117
135
  ```
@@ -138,6 +156,8 @@ function Counter() {
138
156
 
139
157
  当任何人对值做出修改时,它会把最新的值立刻更新到所有人的屏幕上。
140
158
 
159
+ 注意:返回的快照为只读,请勿对其做出操作!快照仅用于在 React 的 XML 中读取数据。其他所有操作(如赋值或订阅等)请操作原 RhineVar 对象。
160
+
141
161
  <br/>
142
162
 
143
163
  #### [点击查看 完整文档 LEARN_zh.md](assets/documents/LEARN_zh.md)
@@ -8,7 +8,7 @@ function useRhine(proxy) {
8
8
  const [state, setState] = (0, react_1.useState)(getState);
9
9
  (0, react_1.useEffect)(() => {
10
10
  var _a;
11
- proxy.subscribe(() => {
11
+ proxy.subscribeDeep(() => {
12
12
  // TODO: 提高性能
13
13
  setState(getState);
14
14
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhine-var",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
4
4
  "description": "Variables that support multi-user collaboration and persistence, making collaboration and variable operations as simple as possible, with strict and well-defined type hints.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",