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

operators for array-stores #164

Open
AlexandrHoroshih opened this issue Sep 2, 2021 Discussed in #147 · 0 comments
Open

operators for array-stores #164

AlexandrHoroshih opened this issue Sep 2, 2021 Discussed in #147 · 0 comments
Labels
RFC Some new feature that should be discussed

Comments

@AlexandrHoroshih
Copy link
Member

Discussed in #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:

sampleForEach({
  source: Store<T[]> | Event<T[]>,
  clock,
  target: Event<T> | Effect<T> // will be run for Every T from T[] in source
})

Live example:
https://share.effector.dev/vx6hm1il

Possible use case:

const runTransaction = createEvent<Transaction>()
const runTransactionGroup = createEvent<Transaction[]>()

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"}
```</div>
@sergeysova sergeysova added the feature New functionality label Sep 20, 2021
@sergeysova sergeysova added RFC Some new feature that should be discussed and removed feature New functionality labels Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Some new feature that should be discussed
Projects
None yet
Development

No branches or pull requests

2 participants