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
- export function applyTransactionAsyncUpdate(grid, newData, getId, bufTable, option) {
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
- const ref = ('gridRef' in params) ? params.gridRef : undefined;
44
- if (ref?.current?.api?.getRowNode)
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 newData = 'newData' in params ? params.newData : undefined;
82
- const removeData = 'removeData' in params ? params.removeData : undefined;
83
- // Сначала удаляем — чтобы async update не конфликтовал
84
- if (removeData?.length) {
85
- const toRemove = [];
86
- removeData.forEach(e => {
87
- const id = getId(e);
88
- delete bufTable[id];
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
- applyTransactionAsyncUpdate(g, newData, getId, bufTable, op);
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
- const m = map.get(bufTable);
105
- const newData = 'newData' in params ? params.newData : undefined;
106
- const removeData = 'removeData' in params ? params.removeData : undefined;
107
- if (newData)
108
- newData.forEach(e => {
109
- const id = getId(e);
110
- m?.add(id);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wenay-react2",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "Common react",
5
5
  "strict": true,
6
6
  "main": "dist/index.js",