@next-core/brick-utils 2.40.0 → 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 +11 -0
- package/dist/index.bundle.js +63 -0
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +63 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/makeThrottledAggregation.d.ts +13 -0
- package/dist/types/makeThrottledAggregation.spec.d.ts +1 -0
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -23075,5 +23075,67 @@ function beforeVisitInstalledAppsFactory(collection) {
|
|
|
23075
23075
|
};
|
|
23076
23076
|
}
|
|
23077
23077
|
|
|
23078
|
-
|
|
23078
|
+
var poolMap = new Map();
|
|
23079
|
+
|
|
23080
|
+
/**
|
|
23081
|
+
* Make a throttled aggregation function.
|
|
23082
|
+
*
|
|
23083
|
+
* Note: the `id` should be a primitive value, typically a string or a number.
|
|
23084
|
+
* If the `id` must be an array or an object, encode it in JSON.
|
|
23085
|
+
*
|
|
23086
|
+
* @param namespace Should be unique for each purpose.
|
|
23087
|
+
* @param request Accept ids, fire request and return the promise.
|
|
23088
|
+
* @param select Select the specific data for a specific id in the aggregated result.
|
|
23089
|
+
* @param wait Throttle wait time in milliseconds, defaults to 100.
|
|
23090
|
+
*/
|
|
23091
|
+
function makeThrottledAggregation(namespace, request, select) {
|
|
23092
|
+
var wait = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 100;
|
|
23093
|
+
// Each namespace share a pool.
|
|
23094
|
+
var pool = poolMap.get(namespace);
|
|
23095
|
+
|
|
23096
|
+
if (!pool) {
|
|
23097
|
+
pool = {
|
|
23098
|
+
current: null,
|
|
23099
|
+
fullIds: new Map()
|
|
23100
|
+
};
|
|
23101
|
+
poolMap.set(namespace, pool);
|
|
23102
|
+
}
|
|
23103
|
+
|
|
23104
|
+
function enqueue(id) {
|
|
23105
|
+
var aggregatedIds = new Set();
|
|
23106
|
+
aggregatedIds.add(id);
|
|
23107
|
+
var promise = new Promise((resolve, reject) => {
|
|
23108
|
+
setTimeout(() => {
|
|
23109
|
+
pool.current = null;
|
|
23110
|
+
request([...aggregatedIds]).then(resolve, reject);
|
|
23111
|
+
}, wait);
|
|
23112
|
+
});
|
|
23113
|
+
return {
|
|
23114
|
+
promise,
|
|
23115
|
+
aggregatedIds
|
|
23116
|
+
};
|
|
23117
|
+
}
|
|
23118
|
+
|
|
23119
|
+
return function (id) {
|
|
23120
|
+
var cached = pool.fullIds.get(id);
|
|
23121
|
+
|
|
23122
|
+
if (cached) {
|
|
23123
|
+
return cached.then(r => select(r, id));
|
|
23124
|
+
}
|
|
23125
|
+
|
|
23126
|
+
if (pool.current) {
|
|
23127
|
+
pool.current.aggregatedIds.add(id);
|
|
23128
|
+
} else {
|
|
23129
|
+
pool.current = enqueue(id);
|
|
23130
|
+
}
|
|
23131
|
+
|
|
23132
|
+
var {
|
|
23133
|
+
promise
|
|
23134
|
+
} = pool.current;
|
|
23135
|
+
pool.fullIds.set(id, promise);
|
|
23136
|
+
return promise.then(r => select(r, id));
|
|
23137
|
+
};
|
|
23138
|
+
}
|
|
23139
|
+
|
|
23140
|
+
export { JsonStorage, PrecookFunctionVisitor, PrecookVisitor, asyncProcessBrick, asyncProcessStoryboard, collectBricksByCustomTemplates, computeRealRoutePath, convertValueByPrecision, cook, createProviderClass, debounceByAnimationFrame, deepFreeze, formatValue, getDependencyMapOfContext, getDepsOfTemplates, getDllAndDepsByResource, getDllAndDepsOfBricks, getDllAndDepsOfStoryboard, getTemplateDepsOfStoryboard, hasOwnProperty$1 as hasOwnProperty, inject, isBrickNode, isCustomTemplateNode, isEvaluable, isObject, isRouteNode, isSnippetNode, lint, loadScript, makeThrottledAggregation, mapCustomApisToNameAndNamespace, matchPath, normalizeBuilderNode, normalizeMenu, parseForAnalysis, precook, precookFunction, preevaluate, prefetchScript, resolveContextConcurrently, restoreDynamicTemplates, scanAppGetMenuInAny, scanAppGetMenuInStoryboard, scanBricksInBrickConf, scanBricksInStoryboard, scanCustomApisInStoryboard, scanI18NInAny, scanI18NInStoryboard, scanInstalledAppsInStoryboard, scanPermissionActionsInAny, scanPermissionActionsInStoryboard, scanProcessorsInAny, scanProcessorsInStoryboard, scanRouteAliasInStoryboard, scanStoryboard, scanTemplatesInBrick, scanTemplatesInStoryboard, shouldAllowRecursiveEvaluations, smartDisplayForEvaluableString, syncResolveContextConcurrently, toPath, tokTypes_1 as tokTypes, trackContext, trackState, trackUsedContext, trackUsedState, transform, transformAndInject, visitStoryboardExpressions, visitStoryboardFunctions };
|
|
23079
23141
|
//# sourceMappingURL=index.esm.js.map
|