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

Using an array of units with split #1037

Open
mkhoussid opened this issue Dec 27, 2023 · 1 comment
Open

Using an array of units with split #1037

mkhoussid opened this issue Dec 27, 2023 · 1 comment
Labels
question Further information is requested

Comments

@mkhoussid
Copy link

mkhoussid commented Dec 27, 2023

Suppose the following:

import { createStore, combine, createEvent } from 'effector';

const handleSendMessage = createEvent();
const editMessage = createEvent();

const $messageInputFieldText = createStore('');
const $message =  createStore({ text: 'hello' });
const $editingMessage = createStore();

const $editingMessage.on(editMessage, (_, message) => message);

split({
	source: [$editingMessage, $messageInputFieldText],
	clock: handleSendMessage,
	match: ([editingMessage]) => editingMessage ? 'updateMessage' : 'appendPendingChatMessage',
	cases: {
		updateMessage: ([editingMessage, messageInputFieldText]) => {
			console.log(`Updating message ${editingMessage.id} with text ${messageInputFieldText}`);
		},
		appendPendingChatMessage: ([, messageInputFieldText]) => {
			console.log(`creating new message with text ${messageInputFieldText}`);
		},
	},
});

editMessage($message.getState());
handleSendMessage();

This throws an error,

source must be a unit

Any way to get this to work or waiting until/if split starts supporting an array of units?

@mkhoussid mkhoussid added the question Further information is requested label Dec 27, 2023
@sergeysova
Copy link
Collaborator

You can use combine

split({
  clock: handleSendMessage,
  source: combine([$editingMessage, $messageInputFieldText]),
  // ...
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants