effector / effector/patronum

operators for array-stores

Open
#164 0 comments 2 reactions 0 assignees View on GitHub
RFC
Dominant language
TypeScript
Stars
312
Forks
48
PR merge metrics
No merged PRs in 30d

Description

### Discussed in https://github.com/effector/patronum/discussions/147

Originally posted by **AlexandrHoroshih** June 4, 2021
At the moment there is no option in basic effector api to do something like `call that event on every item from this array in store or in event payload`

Idea is to create operator which is something like this:

```ts
sampleForEach({
source: Store | Event,
clock,
target: Event | Effect // will be run for Every T from T[] in source
})
```
Live example:
https://share.effector.dev/vx6hm1il

Possible use case:

```ts
const runTransaction = createEvent()
const runTransactionGroup = createEvent()

sampleForEach({
source: runTransactionGroup,
target: runTransaction, // run all transactions from group one-by-one
})

runTransaction.watch(t => console.log('Handling transaction...', t)) // for example, we just logging all transactions

runTransaction({
type: 'transactionType',
body: 'Single',
})

runTransactionGroup([
{
type: 'transactionType',
body: 'group1',
},
{
type: 'transactionType',
body: 'group2',
},
{
type: 'transactionType',
body: 'group3',
},
])

// in logs:
Handling transaction...
{type: "transactionType", body: "Single"}

Handling transaction...
{type: "transactionType", body: "group1"}

Handling transaction...
{type: "transactionType", body: "group2"}

Handling transaction...
{type: "transactionType", body: "group3"}
```

Contributor guide

Open the contributing guide

Research direction

Start with discussion 147 and the linked live example to understand the proposed sampleForEach API and its expected behavior for Store or Event arrays targeting an Event or Effect. Done means the design is settled and the operator's one-by-one dispatch semantics, supported inputs, and tests are specified.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.