@next-core/brick-utils 2.39.5 → 2.41.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/CHANGELOG.md CHANGED
@@ -3,6 +3,36 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.41.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.40.0...@next-core/brick-utils@2.41.0) (2022-09-07)
7
+
8
+
9
+ ### Features
10
+
11
+ * support makeThrottledAggregation ([b44074c](https://github.com/easyops-cn/next-core/commit/b44074ca2d11c080a6e9d64212a81a5a3a154c8c))
12
+
13
+
14
+
15
+
16
+
17
+ # [2.40.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.39.6...@next-core/brick-utils@2.40.0) (2022-09-06)
18
+
19
+
20
+ ### Features
21
+
22
+ * support to use contract in widgets ([25b3337](https://github.com/easyops-cn/next-core/commit/25b333724f9c45131b209845a7caef3e8597888d))
23
+
24
+
25
+
26
+
27
+
28
+ ## [2.39.6](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.39.5...@next-core/brick-utils@2.39.6) (2022-09-06)
29
+
30
+ **Note:** Version bump only for package @next-core/brick-utils
31
+
32
+
33
+
34
+
35
+
6
36
  ## [2.39.5](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.39.4...@next-core/brick-utils@2.39.5) (2022-09-05)
7
37
 
8
38
  **Note:** Version bump only for package @next-core/brick-utils
@@ -849,6 +849,7 @@
849
849
  var collection = [];
850
850
  collectionByTpl.set(tpl.name, collection);
851
851
  collectBricksInBrickConfs(tpl.bricks, collection);
852
+ collectBricksInContext(tpl.state, collection);
852
853
  });
853
854
  }
854
855
 
@@ -23079,6 +23080,68 @@
23079
23080
  };
23080
23081
  }
23081
23082
 
23083
+ var poolMap = new Map();
23084
+
23085
+ /**
23086
+ * Make a throttled aggregation function.
23087
+ *
23088
+ * Note: the `id` should be a primitive value, typically a string or a number.
23089
+ * If the `id` must be an array or an object, encode it in JSON.
23090
+ *
23091
+ * @param namespace Should be unique for each purpose.
23092
+ * @param request Accept ids, fire request and return the promise.
23093
+ * @param select Select the specific data for a specific id in the aggregated result.
23094
+ * @param wait Throttle wait time in milliseconds, defaults to 100.
23095
+ */
23096
+ function makeThrottledAggregation(namespace, request, select) {
23097
+ var wait = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 100;
23098
+ // Each namespace share a pool.
23099
+ var pool = poolMap.get(namespace);
23100
+
23101
+ if (!pool) {
23102
+ pool = {
23103
+ current: null,
23104
+ fullIds: new Map()
23105
+ };
23106
+ poolMap.set(namespace, pool);
23107
+ }
23108
+
23109
+ function enqueue(id) {
23110
+ var aggregatedIds = new Set();
23111
+ aggregatedIds.add(id);
23112
+ var promise = new Promise((resolve, reject) => {
23113
+ setTimeout(() => {
23114
+ pool.current = null;
23115
+ request([...aggregatedIds]).then(resolve, reject);
23116
+ }, wait);
23117
+ });
23118
+ return {
23119
+ promise,
23120
+ aggregatedIds
23121
+ };
23122
+ }
23123
+
23124
+ return function (id) {
23125
+ var cached = pool.fullIds.get(id);
23126
+
23127
+ if (cached) {
23128
+ return cached.then(r => select(r, id));
23129
+ }
23130
+
23131
+ if (pool.current) {
23132
+ pool.current.aggregatedIds.add(id);
23133
+ } else {
23134
+ pool.current = enqueue(id);
23135
+ }
23136
+
23137
+ var {
23138
+ promise
23139
+ } = pool.current;
23140
+ pool.fullIds.set(id, promise);
23141
+ return promise.then(r => select(r, id));
23142
+ };
23143
+ }
23144
+
23082
23145
  Object.defineProperty(exports, 'pipes', {
23083
23146
  enumerable: true,
23084
23147
  get: function () { return pipes.pipes; }
@@ -23088,6 +23151,7 @@
23088
23151
  exports.PrecookVisitor = PrecookVisitor;
23089
23152
  exports.asyncProcessBrick = asyncProcessBrick;
23090
23153
  exports.asyncProcessStoryboard = asyncProcessStoryboard;
23154
+ exports.collectBricksByCustomTemplates = collectBricksByCustomTemplates;
23091
23155
  exports.computeRealRoutePath = computeRealRoutePath;
23092
23156
  exports.convertValueByPrecision = convertValueByPrecision;
23093
23157
  exports.cook = cook;
@@ -23111,6 +23175,7 @@
23111
23175
  exports.isSnippetNode = isSnippetNode;
23112
23176
  exports.lint = lint;
23113
23177
  exports.loadScript = loadScript;
23178
+ exports.makeThrottledAggregation = makeThrottledAggregation;
23114
23179
  exports.mapCustomApisToNameAndNamespace = mapCustomApisToNameAndNamespace;
23115
23180
  exports.matchPath = matchPath;
23116
23181
  exports.normalizeBuilderNode = normalizeBuilderNode;