effector / effector/reflect

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

Open
#34 1 comment 2 reactions 0 assignees View on GitHub
RFC
Dominant language
TypeScript
Stars
90
Forks
12
PR merge metrics
No merged PRs in 30d

Description

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:
```js
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 = () =>

admin>

const UserComponent = () =>
user
```

```js
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 = () =>
const CreateYourFirstProject = () =>
```

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.