Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A proposal to rework the operator variant or add a new, more flexible one. #34

Open
MiiZZo opened this issue Jan 20, 2022 · 1 comment
Labels

Comments

@MiiZZo
Copy link

MiiZZo commented Jan 20, 2022

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.

@MiiZZo MiiZZo mentioned this issue Jan 20, 2022
@AlexandrHoroshih
Copy link
Member

AlexandrHoroshih commented Feb 10, 2022

@MiiZZo Hi!
Sorry it took so long to reply

The idea sounds really cool, i like this api 👍

But I don't really like the idea of making it a new operator, since it more like an extended version of current variant - it would be confusing to have a few operators for the same purpose 🤔

I think, it could very well be an extension of variant, what do you think?
This way current variant will be basically a shorthand of your, more flexible, version

As i see it based on your PR - it could be merged with variant easily 🤔

@sergeysova sergeysova added the RFC label Aug 3, 2022
@MiiZZo MiiZZo mentioned this issue Jul 8, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants