@zentryhq/ui-utils 1.0.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/dist/cn.d.ts +2 -0
- package/dist/cn.js +5 -0
- package/dist/debounced-fetcher.d.ts +10 -0
- package/dist/debounced-fetcher.js +33 -0
- package/dist/merge-refs.d.ts +1 -0
- package/dist/merge-refs.jsx +12 -0
- package/package.json +51 -0
package/dist/cn.d.ts
ADDED
package/dist/cn.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debounces a fetchable function into a single call.
|
|
3
|
+
*/
|
|
4
|
+
export declare class DebounceFetcher<ARGS, RES> {
|
|
5
|
+
private _batchableFetch;
|
|
6
|
+
private _aggregated;
|
|
7
|
+
private _rafId;
|
|
8
|
+
constructor(_batchableFetch: (batchedArgs: ARGS[]) => Promise<RES[]>);
|
|
9
|
+
fetch(args: ARGS): Promise<RES | null>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Resolvable } from "@zentryhq/utils/resolvable";
|
|
2
|
+
/**
|
|
3
|
+
* Debounces a fetchable function into a single call.
|
|
4
|
+
*/
|
|
5
|
+
export class DebounceFetcher {
|
|
6
|
+
_batchableFetch;
|
|
7
|
+
_aggregated = [];
|
|
8
|
+
_rafId = null;
|
|
9
|
+
constructor(_batchableFetch) {
|
|
10
|
+
this._batchableFetch = _batchableFetch;
|
|
11
|
+
}
|
|
12
|
+
fetch(args) {
|
|
13
|
+
const resolvable = new Resolvable();
|
|
14
|
+
this._aggregated.push({ resolvable, args });
|
|
15
|
+
if (!this._rafId) {
|
|
16
|
+
this._rafId = requestAnimationFrame(() => {
|
|
17
|
+
const aggregated = [...this._aggregated];
|
|
18
|
+
this._aggregated = [];
|
|
19
|
+
this._rafId = null;
|
|
20
|
+
const doThing = async () => {
|
|
21
|
+
// fetch here with all arguments and return
|
|
22
|
+
const allPayloads = aggregated.map((a) => a.args);
|
|
23
|
+
const result = await this._batchableFetch(allPayloads);
|
|
24
|
+
for (let i = 0; i < aggregated.length; i++) {
|
|
25
|
+
aggregated[i].resolvable.resolve(result[i]);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
void doThing();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return resolvable.wait();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>): React.RefCallback<T>;
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zentryhq/ui-utils",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "UI Utility module used by the team at Zentry",
|
|
5
|
+
"homepage": "https://github.com/zentryHQ/common",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/zentryHQ/common"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/zentryHQ/common"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Zentry",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
"./cn": {
|
|
22
|
+
"types": "./dist/cn.d.ts",
|
|
23
|
+
"default": "./dist/cn.js"
|
|
24
|
+
},
|
|
25
|
+
"./merge-refs": {
|
|
26
|
+
"types": "./dist/merge-refs.d.ts",
|
|
27
|
+
"default": "./dist/merge-refs.js"
|
|
28
|
+
},
|
|
29
|
+
"./debounced-fetcher": {
|
|
30
|
+
"types": "./dist/debounced-fetcher.d.ts",
|
|
31
|
+
"default": "./dist/debounced-fetcher.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"dev": "tsc --watch",
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"test": "vitest --passWithNoTests"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^22.5.5",
|
|
41
|
+
"typescript": "latest",
|
|
42
|
+
"vitest": "^1.0.0",
|
|
43
|
+
"@types/react": "19.2.14",
|
|
44
|
+
"@types/react-dom": "19.2.3"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@zentryhq/utils": "workspace:*",
|
|
48
|
+
"clsx": "^2.1.1",
|
|
49
|
+
"tailwind-merge": "^3.4.1"
|
|
50
|
+
}
|
|
51
|
+
}
|