The variant operator has a strange limitation in the form of the need to cast the store to a string. It seems to me that its api needs to be reworked in order to make the operator more flexible.
Some example of using:
const $user = createStore({ isAdmin: false });
const Component = cases({
source: $user,
cases: [
{ view: UserComponent, filter: (user) => !user.isAdmin },
{ view: AdminComponent, filter: (user) => user.isAdmin },
],
});
const AdminComponent = () => <div>admin></div>
const UserComponent = () => <div>user</user>
const $projects = createStore([]);
const projectCreated = createEvent();
$projects.on(projectCreated, (projects) => [...projects, {}]);
const Component = cases({
source: $projects,
cases: [
{ view: CreateYourFirstProject, filter: (projects) => projects.length === 0 },
{ view: ProjectsList, filter: (projects) => projects.length > 0 },
],
});
const ProjectsList = () => <list />
const CreateYourFirstProject = () => <button />
I've left the pr with the implementation of this operator (cases) separate from the variant if that idea sounds good.
P.S. I'm not sure, maybe my idea is bad, I'll be grateful if you help me understand this. And please forgive me for my bad english.
The
variantoperator has a strange limitation in the form of the need to cast the store to a string. It seems to me that its api needs to be reworked in order to make the operator more flexible.Some example of using:
I've left the pr with the implementation of this operator (
cases) separate from thevariantif that idea sounds good.P.S. I'm not sure, maybe my idea is bad, I'll be grateful if you help me understand this. And please forgive me for my bad english.