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

Add splitMap support match syntax #123

Open
Fl0pZz opened this issue Nov 16, 2020 · 3 comments · May be fixed by #336
Open

Add splitMap support match syntax #123

Fl0pZz opened this issue Nov 16, 2020 · 3 comments · May be fixed by #336
Labels
enhancement Improvement in existing feature

Comments

@Fl0pZz
Copy link

Fl0pZz commented Nov 16, 2020

From effector doc:

split({
  source: messageReceived,
  match: {
    text: msg => msg.type === 'text',
    audio: msg => msg.type === 'audio',
  },
  cases: createApi(textContent, {
    text: (list, {value}) => [...list, value],
    audio: (list, {duration}) => [...list, `audio ${duration} ms`],
    __: list => [...list, 'unknown message'],
  }),
})
@sergeysova sergeysova changed the title Add splitMap support match syntacsys Add splitMap support match syntax Nov 22, 2020
@sergeysova sergeysova changed the title Add splitMap support match syntax Add splitMap support match syntax Nov 22, 2020
@sergeysova sergeysova added the enhancement Improvement in existing feature label Nov 22, 2020
@sergeysova sergeysova added this to the v1.2 milestone Feb 14, 2021
@sergeysova
Copy link
Member

sergeysova commented Feb 25, 2021

@Fl0pZz Can you write an example for the requested feature?

@sergeysova sergeysova removed this from the v1.2 milestone Feb 3, 2022
@Lonli-Lokli
Copy link

It would be great to support splitMap with clock as split

@Lonli-Lokli
Copy link

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
  },
});

@earthspacon earthspacon linked a pull request Aug 1, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement in existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants