wenay-react2 1.0.18 → 1.0.19
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.
|
@@ -25,10 +25,12 @@ type params<T> = CommonParams<T> & ({
|
|
|
25
25
|
synchronization?: never;
|
|
26
26
|
gridRef?: React.RefObject<GridReadyEvent<T, any> | null | undefined>;
|
|
27
27
|
grid?: GridReadyEvent<T, any> | null | undefined;
|
|
28
|
+
onlyMemo?: boolean;
|
|
28
29
|
} | ({
|
|
29
30
|
newData?: never;
|
|
30
31
|
removeData?: never;
|
|
31
32
|
synchronization: true;
|
|
33
|
+
onlyMemo?: never;
|
|
32
34
|
} & ({
|
|
33
35
|
grid: GridReadyEvent<T, any> | null | undefined;
|
|
34
36
|
gridRef?: never;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
// обертка для упрощения работы с гридом через точку памяти
|
|
1
2
|
const optionsDef = {
|
|
2
3
|
update: true,
|
|
3
4
|
add: true,
|
|
4
5
|
updateBuffer: true,
|
|
5
6
|
sync: false,
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
+
function applyTransactionAsyncUpdate3({ getId, bufTable, option, newData, grid, remove }) {
|
|
8
9
|
const op = { ...optionsDef, ...(option ?? {}) };
|
|
9
10
|
if (!grid?.api.getRowNode)
|
|
10
11
|
return;
|
|
12
|
+
// определяем какие строки надо добавить, а какие только обновить
|
|
11
13
|
const arrNew = [];
|
|
12
14
|
const arr = newData.map(e => {
|
|
13
15
|
const id = getId(e);
|
|
@@ -29,9 +31,13 @@ export function applyTransactionAsyncUpdate(grid, newData, getId, bufTable, opti
|
|
|
29
31
|
return;
|
|
30
32
|
}
|
|
31
33
|
if (arrNew.length && op.add)
|
|
32
|
-
grid.api.applyTransaction({ add: arrNew });
|
|
34
|
+
grid.api.applyTransaction({ add: arrNew, remove: remove }); // для удаления важно только получить ид
|
|
33
35
|
if (arr.length && op.update)
|
|
34
|
-
grid.api.applyTransactionAsync({ update: arr });
|
|
36
|
+
grid.api.applyTransactionAsync({ update: arr, remove: remove });
|
|
37
|
+
}
|
|
38
|
+
// тут нет удаления но эта версия может использовать где то
|
|
39
|
+
export function applyTransactionAsyncUpdate(grid, newData, getId, bufTable, option) {
|
|
40
|
+
return applyTransactionAsyncUpdate3({ getId, option, newData, grid, bufTable });
|
|
35
41
|
}
|
|
36
42
|
const map = new WeakMap();
|
|
37
43
|
export function getUpdateTable(grid, newData, getId, bufTable, option) {
|
|
@@ -40,16 +46,15 @@ export function getUpdateTable(grid, newData, getId, bufTable, option) {
|
|
|
40
46
|
function resolveGrid(params) {
|
|
41
47
|
if (params.grid?.api?.getRowNode)
|
|
42
48
|
return params.grid;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return ref.current;
|
|
49
|
+
if (params.gridRef?.current?.api?.getRowNode)
|
|
50
|
+
return params.gridRef.current;
|
|
46
51
|
return null;
|
|
47
52
|
}
|
|
48
53
|
export function applyTransactionAsyncUpdate2(params) {
|
|
49
|
-
const { getId, bufTable } = params;
|
|
54
|
+
const { getId, bufTable, newData, removeData } = params;
|
|
50
55
|
const op = { ...optionsDef, ...(params.option ?? {}) };
|
|
51
56
|
const g = resolveGrid(params);
|
|
52
|
-
if (g) {
|
|
57
|
+
if (g && params.onlyMemo != true) {
|
|
53
58
|
if (params.synchronization) {
|
|
54
59
|
// === СИНХРОНИЗАЦИЯ: bufTable — истина ===
|
|
55
60
|
const bufIds = new Set(Object.keys(bufTable));
|
|
@@ -78,45 +83,28 @@ export function applyTransactionAsyncUpdate2(params) {
|
|
|
78
83
|
});
|
|
79
84
|
}
|
|
80
85
|
else {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const existing = g.api.getRowNode(id)?.data;
|
|
90
|
-
if (existing)
|
|
91
|
-
toRemove.push(existing);
|
|
92
|
-
});
|
|
93
|
-
if (toRemove.length)
|
|
94
|
-
g.api.applyTransaction({ remove: toRemove });
|
|
95
|
-
}
|
|
86
|
+
const toRemove = [];
|
|
87
|
+
removeData?.forEach(e => {
|
|
88
|
+
const id = getId(e);
|
|
89
|
+
delete bufTable[id];
|
|
90
|
+
const existing = g.api.getRowNode(id)?.data;
|
|
91
|
+
if (existing)
|
|
92
|
+
toRemove.push(existing);
|
|
93
|
+
});
|
|
96
94
|
if (newData?.length)
|
|
97
|
-
|
|
95
|
+
applyTransactionAsyncUpdate3({ grid: g, newData, getId, bufTable, option: op, remove: toRemove });
|
|
98
96
|
}
|
|
99
97
|
}
|
|
100
98
|
else {
|
|
101
|
-
// === ГРИД НЕ ГОТОВ — работаем только с буфером ===
|
|
102
99
|
if (!map.has(bufTable))
|
|
103
100
|
map.set(bufTable, new Set());
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (op.updateBuffer)
|
|
112
|
-
bufTable[id] = { ...(bufTable[id] ?? {}), ...e };
|
|
113
|
-
});
|
|
114
|
-
if (removeData)
|
|
115
|
-
removeData.forEach(e => {
|
|
116
|
-
const id = getId(e);
|
|
117
|
-
m?.delete(id);
|
|
118
|
-
delete bufTable[id];
|
|
119
|
-
});
|
|
101
|
+
newData?.forEach(e => {
|
|
102
|
+
const id = getId(e);
|
|
103
|
+
bufTable[id] = { ...(bufTable[id] ?? {}), ...e };
|
|
104
|
+
});
|
|
105
|
+
removeData?.forEach(e => {
|
|
106
|
+
delete bufTable[getId(e)];
|
|
107
|
+
});
|
|
120
108
|
}
|
|
121
109
|
}
|
|
122
110
|
export function getComparatorGrid(func) {
|