@nordcraft/core 2.0.3 → 2.0.5
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/api/ToddleApiV2.js +5 -0
- package/dist/api/ToddleApiV2.js.map +1 -1
- package/dist/component/ToddleComponent.d.ts +5 -5
- package/dist/component/ToddleComponent.js +17 -13
- package/dist/component/ToddleComponent.js.map +1 -1
- package/dist/component/component.types.d.ts +22 -15
- package/dist/component/component.types.js.map +1 -1
- package/dist/formula/formula.d.ts +1 -1
- package/dist/formula/formula.js +66 -25
- package/dist/formula/formula.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/utils/collections.d.ts +1 -1
- package/dist/utils/collections.js +1 -1
- package/dist/utils/collections.js.map +1 -1
- package/dist/utils/getNodeSelector.js +10 -1
- package/dist/utils/getNodeSelector.js.map +1 -1
- package/dist/utils/measure.d.ts +1 -1
- package/dist/utils/measure.js +18 -4
- package/dist/utils/measure.js.map +1 -1
- package/package.json +1 -1
- package/src/api/ToddleApiV2.ts +5 -0
- package/src/component/ToddleComponent.ts +17 -13
- package/src/component/component.types.ts +28 -14
- package/src/formula/formula.ts +67 -25
- package/src/types.ts +6 -0
- package/src/utils/collections.ts +5 -2
- package/src/utils/getNodeSelector.test.ts +9 -0
- package/src/utils/getNodeSelector.ts +10 -1
- package/src/utils/measure.test.ts +149 -0
- package/src/utils/measure.ts +23 -4
package/src/utils/measure.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
const globalScope: any = typeof globalThis !== 'undefined' ? globalThis : window
|
|
2
|
-
globalScope.__nc_measure_max_depth =
|
|
2
|
+
globalScope.__nc_measure_max_depth =
|
|
3
|
+
typeof sessionStorage !== 'undefined' &&
|
|
4
|
+
sessionStorage.getItem('__nc_measure_max_depth')
|
|
5
|
+
? parseInt(sessionStorage.getItem('__nc_measure_max_depth')!)
|
|
6
|
+
: 10
|
|
3
7
|
globalScope.__nc_measure_enabled =
|
|
4
8
|
typeof sessionStorage !== 'undefined' &&
|
|
5
9
|
sessionStorage.getItem('__nc_measure') === 'true'
|
|
@@ -7,8 +11,10 @@ globalScope.__nc_measure_enabled =
|
|
|
7
11
|
globalScope.__nc_enableMeasure = (enabled = true, maxDepth = 10) => {
|
|
8
12
|
if (enabled) {
|
|
9
13
|
sessionStorage.setItem('__nc_measure', 'true')
|
|
14
|
+
sessionStorage.setItem('__nc_measure_max_depth', String(maxDepth))
|
|
10
15
|
} else {
|
|
11
16
|
sessionStorage.removeItem('__nc_measure')
|
|
17
|
+
sessionStorage.removeItem('__nc_measure_max_depth')
|
|
12
18
|
}
|
|
13
19
|
globalScope.__nc_measure_enabled = enabled
|
|
14
20
|
globalScope.__nc_measure_max_depth = maxDepth
|
|
@@ -18,17 +24,25 @@ let measureCount = 0
|
|
|
18
24
|
const STACK: string[] = []
|
|
19
25
|
const NOOP = () => {}
|
|
20
26
|
|
|
21
|
-
export const measure = (
|
|
27
|
+
export const measure = (
|
|
28
|
+
key: string,
|
|
29
|
+
details: Record<string, unknown>,
|
|
30
|
+
type?: 'component',
|
|
31
|
+
) => {
|
|
22
32
|
if (!globalScope.__nc_measure_enabled) {
|
|
23
33
|
return NOOP
|
|
24
34
|
}
|
|
25
35
|
|
|
26
36
|
const selfIndex = measureCount++
|
|
37
|
+
const selfStackSize = STACK.length
|
|
38
|
+
if (selfStackSize >= globalScope.__nc_measure_max_depth) {
|
|
39
|
+
return NOOP
|
|
40
|
+
}
|
|
27
41
|
if (STACK.length >= globalScope.__nc_measure_max_depth) {
|
|
28
42
|
return NOOP
|
|
29
43
|
}
|
|
30
44
|
|
|
31
|
-
const start = performance.now()
|
|
45
|
+
const start = performance.now() + selfStackSize * 0.001
|
|
32
46
|
STACK.push(key)
|
|
33
47
|
|
|
34
48
|
let _stopped = false
|
|
@@ -38,7 +52,7 @@ export const measure = (key: string, details: Record<string, unknown>) => {
|
|
|
38
52
|
}
|
|
39
53
|
|
|
40
54
|
_stopped = true
|
|
41
|
-
const end = performance.now()
|
|
55
|
+
const end = performance.now() + selfStackSize * 0.001
|
|
42
56
|
const mergedDetails = extraDetails
|
|
43
57
|
? { ...details, ...extraDetails }
|
|
44
58
|
: details
|
|
@@ -50,6 +64,7 @@ export const measure = (key: string, details: Record<string, unknown>) => {
|
|
|
50
64
|
devtools: {
|
|
51
65
|
dataType: 'track-entry',
|
|
52
66
|
track: 'Nordcraft devtools',
|
|
67
|
+
color: COLOR_MAP[type as keyof typeof COLOR_MAP],
|
|
53
68
|
properties: [
|
|
54
69
|
...Object.entries(mergedDetails).map(([k, v]) => [k, String(v)]),
|
|
55
70
|
['Stack', STACK.join(' > ')],
|
|
@@ -63,3 +78,7 @@ export const measure = (key: string, details: Record<string, unknown>) => {
|
|
|
63
78
|
STACK.pop()
|
|
64
79
|
}
|
|
65
80
|
}
|
|
81
|
+
|
|
82
|
+
const COLOR_MAP = {
|
|
83
|
+
component: 'secondary',
|
|
84
|
+
}
|