rhine-var 0.4.2 → 0.4.5
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 +16 -13
- package/README_zh.md +17 -14
- package/dist/core/native/NativeUtils.d.ts.map +1 -1
- package/dist/core/native/NativeUtils.js +7 -0
- package/dist/core/proxy/Proxy.d.ts.map +1 -1
- package/dist/core/proxy/Proxy.js +4 -7
- package/dist/core/proxy/RhineVarItem.js +9 -9
- package/dist/react/hooks/useRhine.d.ts.map +1 -1
- package/dist/react/hooks/useRhine.js +4 -3
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -146,22 +146,25 @@ More information about server develop: [https://docs.yjs.dev/ecosystem/connectio
|
|
|
146
146
|
|
|
147
147
|
## Develop
|
|
148
148
|
|
|
149
|
+
### Preparation (Only needed for the first-time setup)
|
|
149
150
|
```bash
|
|
150
|
-
#
|
|
151
|
-
yarn run watch
|
|
152
|
-
yarn link
|
|
153
|
-
|
|
154
|
-
# start a easy websocket server
|
|
155
|
-
cd test/server
|
|
151
|
+
# Install dependencies
|
|
156
152
|
yarn install
|
|
157
|
-
|
|
153
|
+
# Install dependencies for the NextJs environment debugging project
|
|
154
|
+
yarn run install-next
|
|
155
|
+
# Link this library to the NextJs environment debugging project
|
|
156
|
+
yarn run link-next
|
|
157
|
+
```
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
yarn
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
### Start Debugging
|
|
160
|
+
```bash
|
|
161
|
+
# Enable real-time TypeScript compilation
|
|
162
|
+
yarn run watch
|
|
163
|
+
# Start the temporary local server, default port is 6600
|
|
164
|
+
yarn run server
|
|
165
|
+
# Start the NextJs environment debugging project, default port is 6700
|
|
166
|
+
yarn run next
|
|
167
|
+
# The browser will navigate to http://localhost:6700
|
|
165
168
|
```
|
|
166
169
|
|
|
167
170
|
<br/>
|
package/README_zh.md
CHANGED
|
@@ -163,23 +163,26 @@ yarn start
|
|
|
163
163
|
|
|
164
164
|
欢迎参与 RHINE-VAR 库的共同开发。本库内有基本的服务端,和调试用 NextJS 项目,可以满足大部分开发过程基本需求。
|
|
165
165
|
|
|
166
|
-
```bash
|
|
167
|
-
# 开始 typescript 自动构建更新
|
|
168
|
-
yarn run watch
|
|
169
|
-
yarn link
|
|
170
|
-
|
|
171
|
-
# 开启临时服务端
|
|
172
|
-
cd test/server
|
|
173
|
-
yarn install
|
|
174
|
-
yarn start
|
|
175
166
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
167
|
+
### 准备工作 仅初次使用时需执行
|
|
168
|
+
```bash
|
|
169
|
+
# 安装依赖
|
|
179
170
|
yarn install
|
|
180
|
-
|
|
181
|
-
|
|
171
|
+
# 安装 NextJs 环境调试项目的依赖
|
|
172
|
+
yarn run install-next
|
|
173
|
+
# 链接本库到 NextJs 环境调试项目
|
|
174
|
+
yarn run link-next
|
|
175
|
+
```
|
|
182
176
|
|
|
177
|
+
### 开始调试
|
|
178
|
+
```bash
|
|
179
|
+
# 启用 typescript 实时编译
|
|
180
|
+
yarn run watch
|
|
181
|
+
# 启用临时本地服务端 默认端口6600
|
|
182
|
+
yarn run server
|
|
183
|
+
# 启动 NextJs 环境调试项目 默认端口6700
|
|
184
|
+
yarn run next
|
|
185
|
+
# 浏览器将跳转至 http://localhost:6700
|
|
183
186
|
```
|
|
184
187
|
|
|
185
188
|
<br/>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeUtils.d.ts","sourceRoot":"","sources":["../../../src/core/native/NativeUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,iBAA6B;
|
|
1
|
+
{"version":3,"file":"NativeUtils.d.ts","sourceRoot":"","sources":["../../../src/core/native/NativeUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,iBAA6B;AAK5C,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAE5C;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CA0BnF;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAkBvE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAYtD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAwB1E;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,GAAG,SAAS,CAgB/E;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,GAAG,GAAG,CAgBpD"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.isNative = isNative;
|
|
4
7
|
exports.nativeSet = nativeSet;
|
|
@@ -9,6 +12,7 @@ exports.nativeGet = nativeGet;
|
|
|
9
12
|
exports.jsonToNative = jsonToNative;
|
|
10
13
|
const yjs_1 = require("yjs");
|
|
11
14
|
const DataUtils_1 = require("../utils/DataUtils");
|
|
15
|
+
const RhineVarItem_1 = __importDefault(require("../proxy/RhineVarItem"));
|
|
12
16
|
function isNative(value) {
|
|
13
17
|
return (value instanceof yjs_1.Map) || (value instanceof yjs_1.Array);
|
|
14
18
|
}
|
|
@@ -16,6 +20,9 @@ function nativeSet(target, key, value) {
|
|
|
16
20
|
if (typeof key !== 'string') {
|
|
17
21
|
return false;
|
|
18
22
|
}
|
|
23
|
+
if (value instanceof RhineVarItem_1.default) {
|
|
24
|
+
value = value.native;
|
|
25
|
+
}
|
|
19
26
|
try {
|
|
20
27
|
if (target instanceof yjs_1.Map) {
|
|
21
28
|
target.set(key, value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Proxy.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/Proxy.ts"],"names":[],"mappings":"AACA,OAAO,uBAAgD,6CAAiD;AACxG,OAAO,YAA+C,uBAAkC;AAIxF,OAAO,EAAC,eAAe,EAAE,mBAAmB,EAAC,0BAAqC;AAClF,OAAO,EAAC,MAAM,EAAC,yBAA6B;AAS5C,OAAO,QAAQ,mBAA8B;AAG7C,eAAO,MAAM,aAAa,UAAsB,CAAA;AAChD,eAAO,MAAM,qBAAqB,QAAmB,CAAA;AAGrD,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EACzC,YAAY,EAAE,CAAC,GAAG,MAAM,EACxB,SAAS,EAAE,uBAAuB,GAAG,MAAM,EAC3C,SAAS,GAAE,OAAO,GAAG,MAAc,GAClC,eAAe,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"Proxy.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/Proxy.ts"],"names":[],"mappings":"AACA,OAAO,uBAAgD,6CAAiD;AACxG,OAAO,YAA+C,uBAAkC;AAIxF,OAAO,EAAC,eAAe,EAAE,mBAAmB,EAAC,0BAAqC;AAClF,OAAO,EAAC,MAAM,EAAC,yBAA6B;AAS5C,OAAO,QAAQ,mBAA8B;AAG7C,eAAO,MAAM,aAAa,UAAsB,CAAA;AAChD,eAAO,MAAM,qBAAqB,QAAmB,CAAA;AAGrD,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EACzC,YAAY,EAAE,CAAC,GAAG,MAAM,EACxB,SAAS,EAAE,uBAAuB,GAAG,MAAM,EAC3C,SAAS,GAAE,OAAO,GAAG,MAAc,GAClC,eAAe,CAAC,CAAC,CAAC,CA+CpB;AAGD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC7C,IAAI,EAAE,CAAC,GAAG,MAAM,EAChB,MAAM,GAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,IAAW,GACtD,mBAAmB,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CA2F7C"}
|
package/dist/core/proxy/Proxy.js
CHANGED
|
@@ -70,6 +70,9 @@ function rhineProxy(defaultValue, connector, overwrite = false) {
|
|
|
70
70
|
if ((0, NativeUtils_1.isNative)(value)) {
|
|
71
71
|
Reflect.set(object.origin, key, rhineProxyItem(value, object));
|
|
72
72
|
}
|
|
73
|
+
else {
|
|
74
|
+
Reflect.set(object.origin, key, value);
|
|
75
|
+
}
|
|
73
76
|
});
|
|
74
77
|
}
|
|
75
78
|
else {
|
|
@@ -139,13 +142,7 @@ function rhineProxyItem(data, parent = null) {
|
|
|
139
142
|
return Reflect.set(object, p, value, receiver);
|
|
140
143
|
(0, Logger_1.log)('Proxy.handler.set:', p, 'to', value, ' ', object, receiver);
|
|
141
144
|
value = (0, DataUtils_1.ensureRhineVar)(value, object);
|
|
142
|
-
let result =
|
|
143
|
-
if ((0, DataUtils_1.isObjectOrArray)(value)) {
|
|
144
|
-
result = (0, NativeUtils_1.nativeSet)(object.native, p, value.native);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
result = (0, NativeUtils_1.nativeSet)(object.native, p, value);
|
|
148
|
-
}
|
|
145
|
+
let result = (0, NativeUtils_1.nativeSet)(object.native, p, value);
|
|
149
146
|
if (!result)
|
|
150
147
|
console.error('Failed to set value');
|
|
151
148
|
return result;
|
|
@@ -154,14 +154,14 @@ class RhineVarItem {
|
|
|
154
154
|
if (action === 'add' || action === 'update') {
|
|
155
155
|
value = target.get(key);
|
|
156
156
|
if ((0, DataUtils_1.isObjectOrArray)(value)) {
|
|
157
|
-
Reflect.set(this, key, (0, Proxy_1.rhineProxyItem)(value, this));
|
|
157
|
+
Reflect.set(this.origin, key, (0, Proxy_1.rhineProxyItem)(value, this));
|
|
158
158
|
}
|
|
159
159
|
else {
|
|
160
|
-
Reflect.set(this, key, value);
|
|
160
|
+
Reflect.set(this.origin, key, value);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
else if (action === 'delete') {
|
|
164
|
-
Reflect.deleteProperty(this, key);
|
|
164
|
+
Reflect.deleteProperty(this.origin, key);
|
|
165
165
|
}
|
|
166
166
|
const newValue = key in this ? Reflect.get(this, key) : value;
|
|
167
167
|
(0, Logger_1.log)('Proxy.event: Map', action, key + ':', oldValue, '->', newValue);
|
|
@@ -184,11 +184,11 @@ class RhineVarItem {
|
|
|
184
184
|
if (oldValue instanceof RhineVarItem) {
|
|
185
185
|
oldValue = oldValue.frozenJson();
|
|
186
186
|
}
|
|
187
|
-
Reflect.deleteProperty(this, i);
|
|
187
|
+
Reflect.deleteProperty(this.origin, i);
|
|
188
188
|
for (let k = i + 1; k < target.length + deltaItem.delete; k++) {
|
|
189
189
|
const value = Reflect.get(this, k);
|
|
190
|
-
Reflect.set(this, k - 1, value);
|
|
191
|
-
Reflect.deleteProperty(this, k);
|
|
190
|
+
Reflect.set(this.origin, k - 1, value);
|
|
191
|
+
Reflect.deleteProperty(this.origin, k);
|
|
192
192
|
}
|
|
193
193
|
(0, Logger_1.log)('Proxy.event: Array delete', i + ':', oldValue, '->', undefined);
|
|
194
194
|
this.emit(i, undefined, oldValue, ChangeType_1.ChangeType.Delete, event, transaction);
|
|
@@ -200,13 +200,13 @@ class RhineVarItem {
|
|
|
200
200
|
i++;
|
|
201
201
|
for (let k = target.length - 1; k >= i; k--) {
|
|
202
202
|
const existingValue = Reflect.get(this, k);
|
|
203
|
-
Reflect.set(this, k + 1, existingValue);
|
|
203
|
+
Reflect.set(this.origin, k + 1, existingValue);
|
|
204
204
|
}
|
|
205
205
|
if ((0, DataUtils_1.isObjectOrArray)(value)) {
|
|
206
|
-
Reflect.set(this, i, (0, Proxy_1.rhineProxyItem)(value, this));
|
|
206
|
+
Reflect.set(this.origin, i, (0, Proxy_1.rhineProxyItem)(value, this));
|
|
207
207
|
}
|
|
208
208
|
else {
|
|
209
|
-
Reflect.set(this, i, value);
|
|
209
|
+
Reflect.set(this.origin, i, value);
|
|
210
210
|
}
|
|
211
211
|
const newValue = i in this ? Reflect.get(this, i) : target.get(i);
|
|
212
212
|
(0, Logger_1.log)('Proxy.event: Array add', i, ':', undefined, '->', newValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRhine.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useRhine.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,eAAe,EAAC,yCAAqC;AAE7D,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"useRhine.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useRhine.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,eAAe,EAAC,yCAAqC;AAE7D,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAgB3E"}
|
|
@@ -4,15 +4,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.default = useRhine;
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
function useRhine(proxy) {
|
|
7
|
-
const
|
|
7
|
+
const getState = () => proxy.json();
|
|
8
|
+
const [state, setState] = (0, react_1.useState)(getState);
|
|
8
9
|
(0, react_1.useEffect)(() => {
|
|
9
10
|
var _a;
|
|
10
11
|
proxy.subscribe(() => {
|
|
11
12
|
// TODO: 提高性能
|
|
12
|
-
setState(
|
|
13
|
+
setState(getState);
|
|
13
14
|
});
|
|
14
15
|
(_a = proxy.connector) === null || _a === void 0 ? void 0 : _a.addSyncedListener(() => {
|
|
15
|
-
setState(
|
|
16
|
+
setState(getState);
|
|
16
17
|
});
|
|
17
18
|
}, []);
|
|
18
19
|
return state;
|
package/package.json
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rhine-var",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"prepare": "ts-patch install -s",
|
|
9
|
-
"
|
|
9
|
+
"install-next": "npm install --prefix ./test/debug/next-app",
|
|
10
|
+
"link-next": "npm link && npm link rhine-var --prefix ./test/debug/next-app",
|
|
11
|
+
|
|
10
12
|
"watch": "tsc --watch",
|
|
13
|
+
"server": "npm run start --prefix ./test/server",
|
|
14
|
+
"next": "npm run dev --prefix ./test/debug/next-app",
|
|
15
|
+
|
|
11
16
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
17
|
+
"build": "tsc",
|
|
12
18
|
"publish": "npm publish"
|
|
13
19
|
},
|
|
14
20
|
"author": "RhineAI",
|
|
@@ -40,8 +46,11 @@
|
|
|
40
46
|
"typescript-transform-paths": "^3.5.0"
|
|
41
47
|
},
|
|
42
48
|
"dependencies": {
|
|
43
|
-
"react": "^18.3.1",
|
|
44
49
|
"y-websocket": "^2.0.4",
|
|
45
50
|
"yjs": "^13.6.18"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"react": ">=16.8.0",
|
|
54
|
+
"react-dom": ">=16.8.0"
|
|
46
55
|
}
|
|
47
56
|
}
|