-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add splitMap
support match
syntax
#123
Labels
enhancement
Improvement in existing feature
Comments
sergeysova
changed the title
Add splitMap support match syntacsys
Add splitMap support match syntax
Nov 22, 2020
sergeysova
changed the title
Add splitMap support match syntax
Add Nov 22, 2020
splitMap
support match
syntax
@Fl0pZz Can you write an example for the requested feature? |
It would be great to support |
as an example - I have a websocket event, which should be in one cases send to effect, in other cases sent to another events. Each target in this case will be not the initial event, but a projection from it import { createEvent } from 'effector';
import { splitMap } from 'patronum/split-map';
type WSEvent =
| { type: 'init'; key: string }
| { type: 'increment'; count: number; name: string }
| { type: 'reset'; name: string };
export const websocketEventReceived = createEvent<WSEvent>();
const init = createEvent<string>();
const increment = createEvent<any>();
const reset = createEvent<string>();
const progressFx = createEffect(console.log);
splitMap({
source: websocketEventReceived,
match: {
init: {
filter: (event) => event.type === 'init',
fn: (event) => event.key
},
increment: {
filter: ({ type, ...payload }) => type === 'increment',
fn: ({ type, ...payload }) => payload
},
reset: {
filter: ({ type, name }) => type === 'reset',
fn: ({name}) => name
},
progress: (event) => event.type === 'progress
},
cases: {
init: init,
increment: increment,
reset: reset,
progress: progressFx
},
}); |
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From effector doc:
The text was updated successfully, but these errors were encountered: