@tamagui/timer 1.0.1-beta.211
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/cjs/index.js +77 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/useEvent.js +35 -0
- package/dist/cjs/useEvent.js.map +7 -0
- package/dist/cjs/useGet.js +45 -0
- package/dist/cjs/useGet.js.map +7 -0
- package/dist/esm/index.js +53 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/useEvent.js +11 -0
- package/dist/esm/useEvent.js.map +7 -0
- package/dist/esm/useGet.js +21 -0
- package/dist/esm/useGet.js.map +7 -0
- package/dist/jsx/index.js +3 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/useEvent.js +11 -0
- package/dist/jsx/useEvent.js.map +7 -0
- package/dist/jsx/useGet.js +18 -0
- package/dist/jsx/useGet.js.map +7 -0
- package/package.json +33 -0
- package/readme.md +23 -0
- package/src/index.ts +58 -0
- package/types/index.d.ts +11 -0
- package/types/useEvent.d.ts +4 -0
- package/types/useGet.d.ts +2 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var src_exports = {};
|
|
20
|
+
__export(src_exports, {
|
|
21
|
+
timer: () => timer
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(src_exports);
|
|
24
|
+
function timer() {
|
|
25
|
+
let runs = 0;
|
|
26
|
+
const typesOfRuns = /* @__PURE__ */ new Set();
|
|
27
|
+
const timings = {};
|
|
28
|
+
return {
|
|
29
|
+
start(opts) {
|
|
30
|
+
let start = Date.now();
|
|
31
|
+
const quiet = opts == null ? void 0 : opts.quiet;
|
|
32
|
+
return (strings, ...vars) => {
|
|
33
|
+
const elapsed = Date.now() - start;
|
|
34
|
+
start = Date.now();
|
|
35
|
+
const tag = strings[0];
|
|
36
|
+
typesOfRuns.add(tag);
|
|
37
|
+
runs++;
|
|
38
|
+
timings[tag] ?? (timings[tag] = 0);
|
|
39
|
+
timings[tag] += elapsed;
|
|
40
|
+
if (!quiet) {
|
|
41
|
+
let result = "";
|
|
42
|
+
strings.forEach((str, i) => {
|
|
43
|
+
result += `${str}${i === strings.length - 1 ? "" : vars[i]}`;
|
|
44
|
+
});
|
|
45
|
+
console.log(`${elapsed}ms`.slice(0, 6).padStart(7) + " |", result);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
profile() {
|
|
50
|
+
return {
|
|
51
|
+
timings,
|
|
52
|
+
runs
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
print() {
|
|
56
|
+
const typeRuns = runs / typesOfRuns.size;
|
|
57
|
+
let totalTime = 0;
|
|
58
|
+
const out = [
|
|
59
|
+
`Ran ${typeRuns} per-type, ${runs} total`,
|
|
60
|
+
...[...typesOfRuns].map((name) => {
|
|
61
|
+
const avg = `avg ` + `${timings[name] / typeRuns}`.slice(0, 9).padEnd(9) + "ms";
|
|
62
|
+
const total = timings[name];
|
|
63
|
+
totalTime += total;
|
|
64
|
+
return `${name.slice(0, 14).padStart(15)} | ${avg} | total ${total}ms`;
|
|
65
|
+
}),
|
|
66
|
+
` total ${totalTime}ms`
|
|
67
|
+
].join("\n");
|
|
68
|
+
console.log(out);
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
timer
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-console */\n\n// let it be called as a template string tag function\n\nexport function timer() {\n let runs = 0\n const typesOfRuns = new Set<string>()\n const timings: Record<string, number> = {}\n\n return {\n start(opts?: { quiet?: boolean }) {\n let start = Date.now()\n const quiet = opts?.quiet\n return (strings: TemplateStringsArray, ...vars: any[]) => {\n const elapsed = Date.now() - start\n start = Date.now()\n const tag = strings[0]\n typesOfRuns.add(tag)\n runs++\n timings[tag] ??= 0\n timings[tag] += elapsed\n if (!quiet) {\n let result = ''\n strings.forEach((str, i) => {\n result += `${str}${i === strings.length - 1 ? '' : vars[i]}`\n })\n console.log(`${elapsed}ms`.slice(0, 6).padStart(7) + ' |', result)\n }\n }\n },\n\n profile() {\n return {\n timings,\n runs,\n }\n },\n\n print() {\n const typeRuns = runs / typesOfRuns.size\n let totalTime = 0\n\n const out = [\n `Ran ${typeRuns} per-type, ${runs} total`,\n ...[...typesOfRuns].map((name) => {\n const avg = `avg ` + `${timings[name] / typeRuns}`.slice(0, 9).padEnd(9) + 'ms'\n const total = timings[name]\n totalTime += total\n return `${name.slice(0, 14).padStart(15)} | ${avg} | total ${total}ms`\n }),\n ` total ${totalTime}ms`,\n ].join('\\n')\n\n console.log(out)\n return out\n },\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,SAAS,QAAQ;AACtB,MAAI,OAAO;AACX,QAAM,cAAc,oBAAI,IAAY;AACpC,QAAM,UAAkC,CAAC;AAEzC,SAAO;AAAA,IACL,MAAM,MAA4B;AAChC,UAAI,QAAQ,KAAK,IAAI;AACrB,YAAM,QAAQ,6BAAM;AACpB,aAAO,CAAC,YAAkC,SAAgB;AACxD,cAAM,UAAU,KAAK,IAAI,IAAI;AAC7B,gBAAQ,KAAK,IAAI;AACjB,cAAM,MAAM,QAAQ;AACpB,oBAAY,IAAI,GAAG;AACnB;AACA,wCAAiB;AACjB,gBAAQ,QAAQ;AAChB,YAAI,CAAC,OAAO;AACV,cAAI,SAAS;AACb,kBAAQ,QAAQ,CAAC,KAAK,MAAM;AAC1B,sBAAU,GAAG,MAAM,MAAM,QAAQ,SAAS,IAAI,KAAK,KAAK;AAAA,UAC1D,CAAC;AACD,kBAAQ,IAAI,GAAG,YAAY,MAAM,GAAG,CAAC,EAAE,SAAS,CAAC,IAAI,MAAM,MAAM;AAAA,QACnE;AAAA,MACF;AAAA,IACF;AAAA,IAEA,UAAU;AACR,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,IAEA,QAAQ;AACN,YAAM,WAAW,OAAO,YAAY;AACpC,UAAI,YAAY;AAEhB,YAAM,MAAM;AAAA,QACV,OAAO,sBAAsB;AAAA,QAC7B,GAAG,CAAC,GAAG,WAAW,EAAE,IAAI,CAAC,SAAS;AAChC,gBAAM,MAAM,SAAS,GAAG,QAAQ,QAAQ,WAAW,MAAM,GAAG,CAAC,EAAE,OAAO,CAAC,IAAI;AAC3E,gBAAM,QAAQ,QAAQ;AACtB,uBAAa;AACb,iBAAO,GAAG,KAAK,MAAM,GAAG,EAAE,EAAE,SAAS,EAAE,OAAO,eAAe;AAAA,QAC/D,CAAC;AAAA,QACD,6CAA6C;AAAA,MAC/C,EAAE,KAAK,IAAI;AAEX,cAAQ,IAAI,GAAG;AACf,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useEvent_exports = {};
|
|
20
|
+
__export(useEvent_exports, {
|
|
21
|
+
useEvent: () => useEvent
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useEvent_exports);
|
|
24
|
+
var import_useGet = require("./useGet");
|
|
25
|
+
function useEvent(callback) {
|
|
26
|
+
return (0, import_useGet.useGet)(callback, defaultValue, true);
|
|
27
|
+
}
|
|
28
|
+
const defaultValue = () => {
|
|
29
|
+
throw new Error("Cannot call an event handler while rendering.");
|
|
30
|
+
};
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
useEvent
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=useEvent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/useEvent.ts"],
|
|
4
|
+
"sourcesContent": ["import { useGet } from './useGet'\n\ntype AnyFunction = (...args: any[]) => any\n\nexport function useEvent<T extends AnyFunction>(callback?: T): T {\n return useGet(callback, defaultValue, true) as T\n}\n\nconst defaultValue = () => {\n throw new Error('Cannot call an event handler while rendering.')\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AAIhB,SAAS,SAAgC,UAAiB;AAC/D,aAAO,sBAAO,UAAU,cAAc,IAAI;AAC5C;AAEA,MAAM,eAAe,MAAM;AACzB,QAAM,IAAI,MAAM,+CAA+C;AACjE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useGet_exports = {};
|
|
20
|
+
__export(useGet_exports, {
|
|
21
|
+
useGet: () => useGet
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useGet_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
const isWeb = process.env.TAMAGUI_TARGET === "web";
|
|
26
|
+
const isClient = typeof window !== "undefined";
|
|
27
|
+
const useIsomorphicLayoutEffect = !isWeb || isClient ? import_react.useLayoutEffect : import_react.useEffect;
|
|
28
|
+
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
29
|
+
const curRef = (0, import_react.useRef)(initialValue ?? currentValue);
|
|
30
|
+
useIsomorphicLayoutEffect(() => {
|
|
31
|
+
curRef.current = currentValue;
|
|
32
|
+
});
|
|
33
|
+
return (0, import_react.useCallback)(
|
|
34
|
+
forwardToFunction ? (...args) => {
|
|
35
|
+
var _a;
|
|
36
|
+
return (_a = curRef.current) == null ? void 0 : _a.apply(null, args);
|
|
37
|
+
} : () => curRef.current,
|
|
38
|
+
[]
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
useGet
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=useGet.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/useGet.ts"],
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useLayoutEffect, useRef } from 'react'\n\nconst isWeb = process.env.TAMAGUI_TARGET === 'web'\nconst isClient = typeof window !== 'undefined'\nconst useIsomorphicLayoutEffect = !isWeb || isClient ? useLayoutEffect : useEffect\n\n// keeps a reference to the current value easily\n\nexport function useGet<A>(\n currentValue: A,\n initialValue?: any,\n forwardToFunction?: boolean\n): () => A {\n const curRef = useRef<any>(initialValue ?? currentValue)\n useIsomorphicLayoutEffect(() => {\n curRef.current = currentValue\n })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useCallback(\n forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current,\n []\n )\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgE;AAEhE,MAAM,QAAQ,QAAQ,IAAI,mBAAmB;AAC7C,MAAM,WAAW,OAAO,WAAW;AACnC,MAAM,4BAA4B,CAAC,SAAS,WAAW,+BAAkB;AAIlE,SAAS,OACd,cACA,cACA,mBACS;AACT,QAAM,aAAS,qBAAY,gBAAgB,YAAY;AACvD,4BAA0B,MAAM;AAC9B,WAAO,UAAU;AAAA,EACnB,CAAC;AAED,aAAO;AAAA,IACL,oBAAoB,IAAI,SAAM;AAnBlC;AAmBqC,0BAAO,YAAP,mBAAgB,MAAM,MAAM;AAAA,QAAQ,MAAM,OAAO;AAAA,IAClF,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
function timer() {
|
|
2
|
+
let runs = 0;
|
|
3
|
+
const typesOfRuns = /* @__PURE__ */ new Set();
|
|
4
|
+
const timings = {};
|
|
5
|
+
return {
|
|
6
|
+
start(opts) {
|
|
7
|
+
let start = Date.now();
|
|
8
|
+
const quiet = opts == null ? void 0 : opts.quiet;
|
|
9
|
+
return (strings, ...vars) => {
|
|
10
|
+
const elapsed = Date.now() - start;
|
|
11
|
+
start = Date.now();
|
|
12
|
+
const tag = strings[0];
|
|
13
|
+
typesOfRuns.add(tag);
|
|
14
|
+
runs++;
|
|
15
|
+
timings[tag] ??= 0;
|
|
16
|
+
timings[tag] += elapsed;
|
|
17
|
+
if (!quiet) {
|
|
18
|
+
let result = "";
|
|
19
|
+
strings.forEach((str, i) => {
|
|
20
|
+
result += `${str}${i === strings.length - 1 ? "" : vars[i]}`;
|
|
21
|
+
});
|
|
22
|
+
console.log(`${elapsed}ms`.slice(0, 6).padStart(7) + " |", result);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
profile() {
|
|
27
|
+
return {
|
|
28
|
+
timings,
|
|
29
|
+
runs
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
print() {
|
|
33
|
+
const typeRuns = runs / typesOfRuns.size;
|
|
34
|
+
let totalTime = 0;
|
|
35
|
+
const out = [
|
|
36
|
+
`Ran ${typeRuns} per-type, ${runs} total`,
|
|
37
|
+
...[...typesOfRuns].map((name) => {
|
|
38
|
+
const avg = `avg ` + `${timings[name] / typeRuns}`.slice(0, 9).padEnd(9) + "ms";
|
|
39
|
+
const total = timings[name];
|
|
40
|
+
totalTime += total;
|
|
41
|
+
return `${name.slice(0, 14).padStart(15)} | ${avg} | total ${total}ms`;
|
|
42
|
+
}),
|
|
43
|
+
` total ${totalTime}ms`
|
|
44
|
+
].join("\n");
|
|
45
|
+
console.log(out);
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
timer
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-console */\n\n// let it be called as a template string tag function\n\nexport function timer() {\n let runs = 0\n const typesOfRuns = new Set<string>()\n const timings: Record<string, number> = {}\n\n return {\n start(opts?: { quiet?: boolean }) {\n let start = Date.now()\n const quiet = opts?.quiet\n return (strings: TemplateStringsArray, ...vars: any[]) => {\n const elapsed = Date.now() - start\n start = Date.now()\n const tag = strings[0]\n typesOfRuns.add(tag)\n runs++\n timings[tag] ??= 0\n timings[tag] += elapsed\n if (!quiet) {\n let result = ''\n strings.forEach((str, i) => {\n result += `${str}${i === strings.length - 1 ? '' : vars[i]}`\n })\n console.log(`${elapsed}ms`.slice(0, 6).padStart(7) + ' |', result)\n }\n }\n },\n\n profile() {\n return {\n timings,\n runs,\n }\n },\n\n print() {\n const typeRuns = runs / typesOfRuns.size\n let totalTime = 0\n\n const out = [\n `Ran ${typeRuns} per-type, ${runs} total`,\n ...[...typesOfRuns].map((name) => {\n const avg = `avg ` + `${timings[name] / typeRuns}`.slice(0, 9).padEnd(9) + 'ms'\n const total = timings[name]\n totalTime += total\n return `${name.slice(0, 14).padStart(15)} | ${avg} | total ${total}ms`\n }),\n ` total ${totalTime}ms`,\n ].join('\\n')\n\n console.log(out)\n return out\n },\n }\n}\n"],
|
|
5
|
+
"mappings": "AAIO,SAAS,QAAQ;AACtB,MAAI,OAAO;AACX,QAAM,cAAc,oBAAI,IAAY;AACpC,QAAM,UAAkC,CAAC;AAEzC,SAAO;AAAA,IACL,MAAM,MAA4B;AAChC,UAAI,QAAQ,KAAK,IAAI;AACrB,YAAM,QAAQ,6BAAM;AACpB,aAAO,CAAC,YAAkC,SAAgB;AACxD,cAAM,UAAU,KAAK,IAAI,IAAI;AAC7B,gBAAQ,KAAK,IAAI;AACjB,cAAM,MAAM,QAAQ;AACpB,oBAAY,IAAI,GAAG;AACnB;AACA,gBAAQ,SAAS;AACjB,gBAAQ,QAAQ;AAChB,YAAI,CAAC,OAAO;AACV,cAAI,SAAS;AACb,kBAAQ,QAAQ,CAAC,KAAK,MAAM;AAC1B,sBAAU,GAAG,MAAM,MAAM,QAAQ,SAAS,IAAI,KAAK,KAAK;AAAA,UAC1D,CAAC;AACD,kBAAQ,IAAI,GAAG,YAAY,MAAM,GAAG,CAAC,EAAE,SAAS,CAAC,IAAI,MAAM,MAAM;AAAA,QACnE;AAAA,MACF;AAAA,IACF;AAAA,IAEA,UAAU;AACR,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,IAEA,QAAQ;AACN,YAAM,WAAW,OAAO,YAAY;AACpC,UAAI,YAAY;AAEhB,YAAM,MAAM;AAAA,QACV,OAAO,sBAAsB;AAAA,QAC7B,GAAG,CAAC,GAAG,WAAW,EAAE,IAAI,CAAC,SAAS;AAChC,gBAAM,MAAM,SAAS,GAAG,QAAQ,QAAQ,WAAW,MAAM,GAAG,CAAC,EAAE,OAAO,CAAC,IAAI;AAC3E,gBAAM,QAAQ,QAAQ;AACtB,uBAAa;AACb,iBAAO,GAAG,KAAK,MAAM,GAAG,EAAE,EAAE,SAAS,EAAE,OAAO,eAAe;AAAA,QAC/D,CAAC;AAAA,QACD,6CAA6C;AAAA,MAC/C,EAAE,KAAK,IAAI;AAEX,cAAQ,IAAI,GAAG;AACf,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useGet } from "./useGet";
|
|
2
|
+
function useEvent(callback) {
|
|
3
|
+
return useGet(callback, defaultValue, true);
|
|
4
|
+
}
|
|
5
|
+
const defaultValue = () => {
|
|
6
|
+
throw new Error("Cannot call an event handler while rendering.");
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
useEvent
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useEvent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/useEvent.ts"],
|
|
4
|
+
"sourcesContent": ["import { useGet } from './useGet'\n\ntype AnyFunction = (...args: any[]) => any\n\nexport function useEvent<T extends AnyFunction>(callback?: T): T {\n return useGet(callback, defaultValue, true) as T\n}\n\nconst defaultValue = () => {\n throw new Error('Cannot call an event handler while rendering.')\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,cAAc;AAIhB,SAAS,SAAgC,UAAiB;AAC/D,SAAO,OAAO,UAAU,cAAc,IAAI;AAC5C;AAEA,MAAM,eAAe,MAAM;AACzB,QAAM,IAAI,MAAM,+CAA+C;AACjE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
|
|
2
|
+
const isWeb = process.env.TAMAGUI_TARGET === "web";
|
|
3
|
+
const isClient = typeof window !== "undefined";
|
|
4
|
+
const useIsomorphicLayoutEffect = !isWeb || isClient ? useLayoutEffect : useEffect;
|
|
5
|
+
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
6
|
+
const curRef = useRef(initialValue ?? currentValue);
|
|
7
|
+
useIsomorphicLayoutEffect(() => {
|
|
8
|
+
curRef.current = currentValue;
|
|
9
|
+
});
|
|
10
|
+
return useCallback(
|
|
11
|
+
forwardToFunction ? (...args) => {
|
|
12
|
+
var _a;
|
|
13
|
+
return (_a = curRef.current) == null ? void 0 : _a.apply(null, args);
|
|
14
|
+
} : () => curRef.current,
|
|
15
|
+
[]
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
useGet
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=useGet.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/useGet.ts"],
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useLayoutEffect, useRef } from 'react'\n\nconst isWeb = process.env.TAMAGUI_TARGET === 'web'\nconst isClient = typeof window !== 'undefined'\nconst useIsomorphicLayoutEffect = !isWeb || isClient ? useLayoutEffect : useEffect\n\n// keeps a reference to the current value easily\n\nexport function useGet<A>(\n currentValue: A,\n initialValue?: any,\n forwardToFunction?: boolean\n): () => A {\n const curRef = useRef<any>(initialValue ?? currentValue)\n useIsomorphicLayoutEffect(() => {\n curRef.current = currentValue\n })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useCallback(\n forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current,\n []\n )\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa,WAAW,iBAAiB,cAAc;AAEhE,MAAM,QAAQ,QAAQ,IAAI,mBAAmB;AAC7C,MAAM,WAAW,OAAO,WAAW;AACnC,MAAM,4BAA4B,CAAC,SAAS,WAAW,kBAAkB;AAIlE,SAAS,OACd,cACA,cACA,mBACS;AACT,QAAM,SAAS,OAAY,gBAAgB,YAAY;AACvD,4BAA0B,MAAM;AAC9B,WAAO,UAAU;AAAA,EACnB,CAAC;AAED,SAAO;AAAA,IACL,oBAAoB,IAAI,SAAM;AAnBlC;AAmBqC,0BAAO,YAAP,mBAAgB,MAAM,MAAM;AAAA,QAAQ,MAAM,OAAO;AAAA,IAClF,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useGet } from "./useGet";
|
|
2
|
+
function useEvent(callback) {
|
|
3
|
+
return useGet(callback, defaultValue, true);
|
|
4
|
+
}
|
|
5
|
+
const defaultValue = () => {
|
|
6
|
+
throw new Error("Cannot call an event handler while rendering.");
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
useEvent
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useEvent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/useEvent.ts"],
|
|
4
|
+
"sourcesContent": ["import { useGet } from './useGet'\n\ntype AnyFunction = (...args: any[]) => any\n\nexport function useEvent<T extends AnyFunction>(callback?: T): T {\n return useGet(callback, defaultValue, true) as T\n}\n\nconst defaultValue = () => {\n throw new Error('Cannot call an event handler while rendering.')\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,cAAc;AAIhB,SAAS,SAAgC,UAAiB;AAC/D,SAAO,OAAO,UAAU,cAAc,IAAI;AAC5C;AAEA,MAAM,eAAe,MAAM;AACzB,QAAM,IAAI,MAAM,+CAA+C;AACjE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
|
|
2
|
+
const isWeb = process.env.TAMAGUI_TARGET === "web";
|
|
3
|
+
const isClient = typeof window !== "undefined";
|
|
4
|
+
const useIsomorphicLayoutEffect = !isWeb || isClient ? useLayoutEffect : useEffect;
|
|
5
|
+
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
6
|
+
const curRef = useRef(initialValue ?? currentValue);
|
|
7
|
+
useIsomorphicLayoutEffect(() => {
|
|
8
|
+
curRef.current = currentValue;
|
|
9
|
+
});
|
|
10
|
+
return useCallback(
|
|
11
|
+
forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current,
|
|
12
|
+
[]
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
useGet
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=useGet.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/useGet.ts"],
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useLayoutEffect, useRef } from 'react'\n\nconst isWeb = process.env.TAMAGUI_TARGET === 'web'\nconst isClient = typeof window !== 'undefined'\nconst useIsomorphicLayoutEffect = !isWeb || isClient ? useLayoutEffect : useEffect\n\n// keeps a reference to the current value easily\n\nexport function useGet<A>(\n currentValue: A,\n initialValue?: any,\n forwardToFunction?: boolean\n): () => A {\n const curRef = useRef<any>(initialValue ?? currentValue)\n useIsomorphicLayoutEffect(() => {\n curRef.current = currentValue\n })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useCallback(\n forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current,\n []\n )\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa,WAAW,iBAAiB,cAAc;AAEhE,MAAM,QAAQ,QAAQ,IAAI,mBAAmB;AAC7C,MAAM,WAAW,OAAO,WAAW;AACnC,MAAM,4BAA4B,CAAC,SAAS,WAAW,kBAAkB;AAIlE,SAAS,OACd,cACA,cACA,mBACS;AACT,QAAM,SAAS,OAAY,gBAAgB,YAAY;AACvD,4BAA0B,MAAM;AAC9B,WAAO,UAAU;AAAA,EACnB,CAAC;AAED,SAAO;AAAA,IACL,oBAAoB,IAAI,SAAS,OAAO,SAAS,MAAM,MAAM,IAAI,IAAI,MAAM,OAAO;AAAA,IAClF,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/timer",
|
|
3
|
+
"version": "1.0.1-beta.211",
|
|
4
|
+
"types": "./types/index.d.ts",
|
|
5
|
+
"main": "dist/cjs",
|
|
6
|
+
"module": "dist/esm",
|
|
7
|
+
"files": [
|
|
8
|
+
"src",
|
|
9
|
+
"types",
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tamagui-build",
|
|
14
|
+
"watch": "tamagui-build --watch",
|
|
15
|
+
"lint": "eslint",
|
|
16
|
+
"lint:fix": "yarn lint --fix",
|
|
17
|
+
"clean": "tamagui-build clean",
|
|
18
|
+
"clean:build": "tamagui-build clean:build"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@tamagui/build": "^1.0.1-beta.211"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
"./package.json": "./package.json",
|
|
25
|
+
".": {
|
|
26
|
+
"import": "./dist/esm/index.js",
|
|
27
|
+
"require": "./dist/cjs/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[timer console output screenshot](./screen.png)!
|
|
2
|
+
|
|
3
|
+
```tsx
|
|
4
|
+
import { timer } from '@tamagui/timer'
|
|
5
|
+
|
|
6
|
+
const t = timer()
|
|
7
|
+
|
|
8
|
+
setTimeout(() => {
|
|
9
|
+
t.print()
|
|
10
|
+
}, 3000)
|
|
11
|
+
|
|
12
|
+
function something() {
|
|
13
|
+
const time = t.start()
|
|
14
|
+
|
|
15
|
+
// do stuff
|
|
16
|
+
|
|
17
|
+
time`firstTag`
|
|
18
|
+
|
|
19
|
+
// do stuff
|
|
20
|
+
|
|
21
|
+
time`second`
|
|
22
|
+
}
|
|
23
|
+
```
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
// let it be called as a template string tag function
|
|
4
|
+
|
|
5
|
+
export function timer() {
|
|
6
|
+
let runs = 0
|
|
7
|
+
const typesOfRuns = new Set<string>()
|
|
8
|
+
const timings: Record<string, number> = {}
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
start(opts?: { quiet?: boolean }) {
|
|
12
|
+
let start = Date.now()
|
|
13
|
+
const quiet = opts?.quiet
|
|
14
|
+
return (strings: TemplateStringsArray, ...vars: any[]) => {
|
|
15
|
+
const elapsed = Date.now() - start
|
|
16
|
+
start = Date.now()
|
|
17
|
+
const tag = strings[0]
|
|
18
|
+
typesOfRuns.add(tag)
|
|
19
|
+
runs++
|
|
20
|
+
timings[tag] ??= 0
|
|
21
|
+
timings[tag] += elapsed
|
|
22
|
+
if (!quiet) {
|
|
23
|
+
let result = ''
|
|
24
|
+
strings.forEach((str, i) => {
|
|
25
|
+
result += `${str}${i === strings.length - 1 ? '' : vars[i]}`
|
|
26
|
+
})
|
|
27
|
+
console.log(`${elapsed}ms`.slice(0, 6).padStart(7) + ' |', result)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
profile() {
|
|
33
|
+
return {
|
|
34
|
+
timings,
|
|
35
|
+
runs,
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
print() {
|
|
40
|
+
const typeRuns = runs / typesOfRuns.size
|
|
41
|
+
let totalTime = 0
|
|
42
|
+
|
|
43
|
+
const out = [
|
|
44
|
+
`Ran ${typeRuns} per-type, ${runs} total`,
|
|
45
|
+
...[...typesOfRuns].map((name) => {
|
|
46
|
+
const avg = `avg ` + `${timings[name] / typeRuns}`.slice(0, 9).padEnd(9) + 'ms'
|
|
47
|
+
const total = timings[name]
|
|
48
|
+
totalTime += total
|
|
49
|
+
return `${name.slice(0, 14).padStart(15)} | ${avg} | total ${total}ms`
|
|
50
|
+
}),
|
|
51
|
+
` total ${totalTime}ms`,
|
|
52
|
+
].join('\n')
|
|
53
|
+
|
|
54
|
+
console.log(out)
|
|
55
|
+
return out
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function timer(): {
|
|
2
|
+
start(opts?: {
|
|
3
|
+
quiet?: boolean;
|
|
4
|
+
}): (strings: TemplateStringsArray, ...vars: any[]) => void;
|
|
5
|
+
profile(): {
|
|
6
|
+
timings: Record<string, number>;
|
|
7
|
+
runs: number;
|
|
8
|
+
};
|
|
9
|
+
print(): string;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|