-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathguards.ts
More file actions
45 lines (41 loc) · 1.02 KB
/
guards.ts
File metadata and controls
45 lines (41 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* eslint-disable */
import type { ComponentState } from "../react/useNativeCss";
import type {
ContainerContextValue,
Effect,
VariableContextValue,
} from "../reactivity";
export type RenderGuard =
| ["a", string, any]
| ["d", string, any]
| ["v", string, any]
| ["c", string, Effect];
export function testGuards(
state: ComponentState,
currentProps: any,
inheritedVariables: VariableContextValue,
inheritedContainers: ContainerContextValue,
) {
return state.guards?.some((guard) => {
let result = false;
switch (guard[0]) {
case "a":
// Attribute
result = currentProps?.[guard[1]] !== guard[2];
break;
case "d":
// DataSet
result = currentProps?.dataSet?.[guard[1]] !== guard[2];
break;
case "v":
// Variables
result = inheritedVariables[guard[1]] !== guard[2];
break;
case "c":
// Containers
result = inheritedContainers[guard[1]] !== guard[2];
break;
}
return result;
});
}