@nightingale-elements/nightingale-new-core
Version:
Base Elements for Nightingale Components
41 lines • 1.72 kB
TypeScript
/** Helper for running potentially time-consuming "refresh" actions (e.g. canvas draw) in a non-blocking way.
* If the caller calls `requestRefresh()`, this call returns immediately but it is guaranteed
* that `refresh` will be run asynchronously in the future.
* If the caller calls `requestRefresh()` multiple times, it is NOT guaranteed
* that `refresh` will be run the same number of times, only that it will be run
* at least once after the last call to `requestRefresh()`. */
export interface Refresher {
requestRefresh: () => void;
}
export declare function Refresher(refresh: () => void): Refresher;
/** Helper for deciding when to skip potentially time-consuming actions (e.g. canvas draw).
* Assumes that we can skip if the "stamp" value has not changed.
* Example usage:
* ```
* const stamp = new Stamp(() => {
* // Compute current stamp value
* });
* ...
* if (stamp.update().changed){
* // Run stuff
* } else {
* // Skip stuff
* }
* ``` */
export declare class Stamp {
/** Function that returns current stamp value. */
readonly stampFunction: () => Record<string, unknown>;
constructor(
/** Function that returns current stamp value. */
stampFunction: () => Record<string, unknown>);
private currentStampValue;
/** Update the current stamp value (using the return value of `stampFunction`).
* Return `true` if the stamp value has changed since the last `update`, `false` otherwise.
* (Stamp value comparison is performed by shallow object comparison.) */
update(): {
oldValue: Record<string, unknown>;
newValue: Record<string, unknown>;
changed: boolean;
};
}
//# sourceMappingURL=refresher.d.ts.map