Skip to content

operator cases#35

Closed
MiiZZo wants to merge 2 commits intoeffector:masterfrom
MiiZZo:master
Closed

operator cases#35
MiiZZo wants to merge 2 commits intoeffector:masterfrom
MiiZZo:master

Conversation

@MiiZZo
Copy link

@MiiZZo MiiZZo commented Jan 20, 2022

issue #34
New operator that more flexible than variant operator.
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 added an implementation of operator cases and tests for no-ssr but some tests fail and i don't know why.

@sergeysova sergeysova added this to the v9.0 milestone Jun 13, 2023
@MiiZZo MiiZZo closed this by deleting the head repository Jul 8, 2023
@MiiZZo MiiZZo mentioned this pull request Jul 8, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants