orange-orm 4.2.0-beta.4 → 4.2.0-beta.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/package.json +1 -1
- package/src/client/cloneFromDb.js +16 -3
- package/src/client/index.js +36 -4
package/package.json
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
let dateToISOString = require('../dateToISOString');
|
|
2
2
|
|
|
3
3
|
function cloneFromDbFast(obj) {
|
|
4
|
-
if (obj === null || typeof obj !== 'object')
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
if (obj === null || typeof obj !== 'object')
|
|
5
|
+
return obj;
|
|
6
|
+
if (Array.isArray(obj)) {
|
|
7
|
+
const arrClone = [];
|
|
8
|
+
for (let i = 0; i < obj.length; i++) {
|
|
9
|
+
arrClone[i] = cloneFromDbFast(obj[i]);
|
|
10
|
+
}
|
|
11
|
+
return arrClone;
|
|
12
|
+
}
|
|
13
|
+
const clone = {};
|
|
14
|
+
const keys = Object.keys(obj);
|
|
15
|
+
for (let i = 0; i < keys.length; i++) {
|
|
16
|
+
const key = keys[i];
|
|
17
|
+
clone[key] = cloneFromDbFast(obj[key]);
|
|
18
|
+
}
|
|
19
|
+
return clone;
|
|
7
20
|
}
|
|
8
21
|
|
|
9
22
|
function cloneRegular(obj) {
|
package/src/client/index.js
CHANGED
|
@@ -483,9 +483,12 @@ function rdbClient(options = {}) {
|
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
};
|
|
486
|
-
|
|
486
|
+
|
|
487
|
+
let watcher = onChange(array, () => {
|
|
488
|
+
rootMap.set(array, { json: cloneFromDb(array, fast), strategy, originalArray: [...array] });
|
|
489
|
+
});
|
|
490
|
+
let innerProxy = new Proxy(watcher, handler);
|
|
487
491
|
//todo
|
|
488
|
-
rootMap.set(array, { json: cloneFromDb(array, fast), strategy, originalArray: [...array] });
|
|
489
492
|
if (strategy !== undefined) {
|
|
490
493
|
const { limit, ...cleanStrategy } = { ...strategy };
|
|
491
494
|
fetchingStrategyMap.set(array, cleanStrategy);
|
|
@@ -517,8 +520,10 @@ function rdbClient(options = {}) {
|
|
|
517
520
|
}
|
|
518
521
|
|
|
519
522
|
};
|
|
520
|
-
let
|
|
521
|
-
|
|
523
|
+
let watcher = onChange(row, () => {
|
|
524
|
+
rootMap.set(row, { json: cloneFromDb(row, fast), strategy });
|
|
525
|
+
});
|
|
526
|
+
let innerProxy = new Proxy(watcher, handler);
|
|
522
527
|
fetchingStrategyMap.set(row, strategy);
|
|
523
528
|
return innerProxy;
|
|
524
529
|
}
|
|
@@ -1004,4 +1009,31 @@ function column(path, ...previous) {
|
|
|
1004
1009
|
|
|
1005
1010
|
}
|
|
1006
1011
|
|
|
1012
|
+
function onChange(target, onChange) {
|
|
1013
|
+
|
|
1014
|
+
let notified = false;
|
|
1015
|
+
const handler = {
|
|
1016
|
+
get(target, prop, receiver) {
|
|
1017
|
+
const value = Reflect.get(target, prop, receiver);
|
|
1018
|
+
if (typeof value === 'object' && value !== null) {
|
|
1019
|
+
return new Proxy(value, handler);
|
|
1020
|
+
}
|
|
1021
|
+
return value;
|
|
1022
|
+
},
|
|
1023
|
+
set(target, prop, value, receiver) {
|
|
1024
|
+
if (!notified) {
|
|
1025
|
+
notified = true;
|
|
1026
|
+
onChange(JSON.stringify(target));
|
|
1027
|
+
}
|
|
1028
|
+
return Reflect.set(target, prop, value, receiver);
|
|
1029
|
+
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
return new Proxy(target, handler);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
|
|
1007
1039
|
module.exports = rdbClient();
|