@epam/uui-db 5.7.2 → 5.8.1-alpha.0
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/index.esm.js +62 -3
- package/index.esm.js.map +1 -1
- package/index.js +62 -3
- package/index.js.map +1 -1
- package/package.json +5 -12
- package/src/DbRef.d.ts.map +1 -1
- package/src/IxSet.d.ts.map +1 -1
- package/src/batch.d.ts +10 -0
- package/src/batch.d.ts.map +1 -0
- package/stats.html +32 -28
package/index.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import shallowEqual from 'shallowequal';
|
|
2
2
|
import zip from 'lodash.zip';
|
|
3
3
|
import transform from 'lodash.transform';
|
|
4
|
-
import isEqual from '
|
|
4
|
+
import isEqual from 'react-fast-compare';
|
|
5
5
|
import * as I from 'immutable';
|
|
6
6
|
import { Seq } from 'immutable';
|
|
7
|
-
import { getFilterPredicate, getSearchFilter, getOrderComparer
|
|
7
|
+
import { getFilterPredicate, getSearchFilter, getOrderComparer } from '@epam/uui-core';
|
|
8
8
|
import groupBy from 'lodash.groupby';
|
|
9
9
|
import map from 'lodash.map';
|
|
10
10
|
import merge from 'lodash.merge';
|
|
@@ -878,6 +878,65 @@ class ListLoadingTracker {
|
|
|
878
878
|
}
|
|
879
879
|
}
|
|
880
880
|
|
|
881
|
+
const delay = (ms = 0) => {
|
|
882
|
+
if (ms <= 0) {
|
|
883
|
+
return Promise.resolve();
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
return new Promise((resolve) => {
|
|
887
|
+
setTimeout(resolve, ms);
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
/** Creates an async function, which can collect several calls to it, and execute them in a single batch via provided callback. */
|
|
892
|
+
function batch(runBatch, options) {
|
|
893
|
+
let delayPromise = Promise.resolve();
|
|
894
|
+
let batchPromise = null;
|
|
895
|
+
let queue = [];
|
|
896
|
+
let nextCallPossibleAtMs = new Date().getTime();
|
|
897
|
+
function batchedFn(arg, callOptions) {
|
|
898
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
899
|
+
options = Object.assign(Object.assign({}, options), callOptions);
|
|
900
|
+
options.throttleMs = options.throttleMs || 0;
|
|
901
|
+
// Enqueue request
|
|
902
|
+
queue.push(arg);
|
|
903
|
+
const resultIndex = queue.length - 1; // an index of current item in queue. Result should be on the same index in batch.
|
|
904
|
+
batchedFn.isBusy = true;
|
|
905
|
+
// Wait current batch to complete
|
|
906
|
+
try {
|
|
907
|
+
yield batchPromise;
|
|
908
|
+
}
|
|
909
|
+
catch (_a) {
|
|
910
|
+
// ignore errors here. They are thrown to previous batch
|
|
911
|
+
}
|
|
912
|
+
// Wait for throttling delay to pass
|
|
913
|
+
yield delayPromise;
|
|
914
|
+
try {
|
|
915
|
+
// Start a batch if there are items.
|
|
916
|
+
// All calls that was awaiting will run this code.
|
|
917
|
+
// Only the first call will run batch, immediately clear the queue, and set batchPromise value
|
|
918
|
+
// Other calls will just await results of this call
|
|
919
|
+
if (queue.length > 0) {
|
|
920
|
+
nextCallPossibleAtMs = new Date().getTime() + options.throttleMs;
|
|
921
|
+
batchPromise = runBatch(queue);
|
|
922
|
+
queue = [];
|
|
923
|
+
}
|
|
924
|
+
const results = yield batchPromise;
|
|
925
|
+
return results === null || results === void 0 ? void 0 : results[resultIndex];
|
|
926
|
+
}
|
|
927
|
+
finally {
|
|
928
|
+
const nowMs = new Date().getTime();
|
|
929
|
+
const delayMs = Math.max(0, nextCallPossibleAtMs - nowMs);
|
|
930
|
+
// It's safe to replace currentPromise here. All other requests are already awaiting
|
|
931
|
+
delayPromise = delay(delayMs);
|
|
932
|
+
batchedFn.isBusy = queue.length > 0;
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
batchedFn.isBusy = false;
|
|
937
|
+
return batchedFn;
|
|
938
|
+
}
|
|
939
|
+
|
|
881
940
|
class DbRef {
|
|
882
941
|
constructor(blank) {
|
|
883
942
|
this.blank = blank;
|
|
@@ -1065,7 +1124,7 @@ class DbRef {
|
|
|
1065
1124
|
}
|
|
1066
1125
|
}
|
|
1067
1126
|
|
|
1068
|
-
const DbContext = createContext(null);
|
|
1127
|
+
const DbContext = /* @__PURE__ */createContext(null);
|
|
1069
1128
|
function useDbRef() {
|
|
1070
1129
|
return useContext(DbContext);
|
|
1071
1130
|
}
|