@callstack/byorg-utils
Advanced tools
Comparing version 0.7.0 to 0.8.0
# @callstack/byorg-utils | ||
## 0.8.0 | ||
### Minor Changes | ||
- ea21cc7: utils: debouncePartialUpdate function for smart debounce handling | ||
## 0.7.0 | ||
@@ -4,0 +10,0 @@ |
export declare const consoleLogger: Logger; | ||
export declare function debouncePartialUpdate(partialUpdate: PartialUpdateFn, { minResponseLength, minUpdateTime }: DebouncePartialUpdateOptions): (text: string) => Promise<void>; | ||
export declare type DebouncePartialUpdateOptions = { | ||
minUpdateTime: number; | ||
minResponseLength: number; | ||
}; | ||
declare function debug(message: string, ...args: unknown[]): void; | ||
@@ -32,2 +39,4 @@ | ||
export declare type PartialUpdateFn = (text: string) => Promise<void>; | ||
export declare function requireEnv(key: string): string; | ||
@@ -34,0 +43,0 @@ |
@@ -141,2 +141,29 @@ // The require scope | ||
;// CONCATENATED MODULE: ./src/debounce.ts | ||
function debouncePartialUpdate(partialUpdate, { minResponseLength, minUpdateTime }) { | ||
let pendingPromise; | ||
let lastUpdate; | ||
return async function(text) { | ||
// Wait for the last update to finish | ||
if (pendingPromise) { | ||
return pendingPromise; | ||
} | ||
// Time-based debounce | ||
if (lastUpdate !== undefined && performance.now() - lastUpdate < minUpdateTime) { | ||
return; | ||
} | ||
// Skip too short initial messages | ||
if (text.length < minResponseLength) { | ||
return; | ||
} | ||
try { | ||
lastUpdate = performance.now(); | ||
pendingPromise = partialUpdate(text); | ||
return await pendingPromise; | ||
} finally{ | ||
pendingPromise = undefined; | ||
} | ||
}; | ||
} | ||
;// CONCATENATED MODULE: ./src/index.ts | ||
@@ -148,2 +175,3 @@ | ||
export { consoleLogger, logger_namespaceObject as logger, requireEnv, withCache }; | ||
export { consoleLogger, debouncePartialUpdate, logger_namespaceObject as logger, requireEnv, withCache }; |
{ | ||
"name": "@callstack/byorg-utils", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14863
372