cambiata
cambiata
SSolidJS
Created by cambiata on 5/29/2024 in #support
Support for discriminated union types?
12 replies
SSolidJS
Created by cambiata on 5/29/2024 in #support
Support for discriminated union types?
If anyone's interested, here's a gist that shows how to deal with discriminated unions both in the view rendering and in the store:
12 replies
SSolidJS
Created by cambiata on 5/29/2024 in #support
Support for discriminated union types?
No keyed involved, so perhaps no performance penalties.
12 replies
SSolidJS
Created by cambiata on 5/29/2024 in #support
Support for discriminated union types?
type UnionType = { type: 'Empty' } | { type: 'Data', value: number };

const App: Component = () => {
const [state, setState] = createStore<UnionType>({ type: 'Empty' });
return <>
<button onClick={_ => setState({ type: 'Data', value: Math.random() })}>Set Data</button>

<Switch>
<Match when={state.type === 'Empty'}>
<h3>Empty</h3>
</Match>
<Match when={state.type === 'Data' && state}>
{state => <h3>Data value: {state().value}</h3>}
</Match>
</Switch>
</>
};
type UnionType = { type: 'Empty' } | { type: 'Data', value: number };

const App: Component = () => {
const [state, setState] = createStore<UnionType>({ type: 'Empty' });
return <>
<button onClick={_ => setState({ type: 'Data', value: Math.random() })}>Set Data</button>

<Switch>
<Match when={state.type === 'Empty'}>
<h3>Empty</h3>
</Match>
<Match when={state.type === 'Data' && state}>
{state => <h3>Data value: {state().value}</h3>}
</Match>
</Switch>
</>
};
12 replies
SSolidJS
Created by cambiata on 5/29/2024 in #support
Support for discriminated union types?
Here's an example:
12 replies
SSolidJS
Created by cambiata on 5/29/2024 in #support
Support for discriminated union types?
Thanks guys! Found what seems to be a decent solution in this thread: https://discord.com/channels/722131463138705510/1074415945986080808/1074415948137758750
12 replies