Skip to content

Commit 65a1815

Browse files
less hacky typecasts
1 parent 0ca6b76 commit 65a1815

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/core/variant.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ export function variantFactory(context: Context) {
5353
}
5454

5555
function View(props: Props) {
56-
const nameOfCaseRaw = context.useUnit($case, config.useUnitConfig);
56+
const nameOfCaseRaw = context.useUnit(
57+
$case as Store<string | boolean>,
58+
config.useUnitConfig,
59+
);
5760
const nameOfCase = (
58-
'if' in config ? ifToVariant(nameOfCaseRaw as any) : nameOfCaseRaw
61+
typeof nameOfCaseRaw === 'string'
62+
? nameOfCaseRaw
63+
: booleanToVariant(nameOfCaseRaw as boolean)
5964
) as Variant;
6065
const Component = cases[nameOfCase] ?? def;
6166

@@ -73,6 +78,6 @@ export function variantFactory(context: Context) {
7378
};
7479
}
7580

76-
function ifToVariant(value: boolean): 'then' | 'else' {
81+
function booleanToVariant(value: boolean): 'then' | 'else' {
7782
return value ? 'then' : 'else';
7883
}

0 commit comments

Comments
 (0)