Skip to content

Conversation

@sergeysova
Copy link
Member

@sergeysova sergeysova commented Apr 23, 2020

import {createEvent, createStore} from 'effector'

const store = createStore(0)
const changedA = createEvent()
const changedB = createEvent()

store.on([changedA, changedB], (state, params) => state + params)

store.watch(value => {
  console.log('updated', value)
})

changedA(2)
// => updated 2

changedB(2)
// => updated 4

store.off(changedB)

@sergeysova sergeysova requested a review from zerobias April 23, 2020 10:40
@vercel vercel bot requested a deployment to Preview April 23, 2020 13:31 Abandoned
@vercel vercel bot requested a deployment to Preview April 23, 2020 13:32 Abandoned
Copy link
Member

@zerobias zerobias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! It's always nice to see such a thorough study 👍

if (!Array.isArray(events)) {
onEvent(events, fn)
} else {
for (const event of events) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! I didn’t even think about it that way

@zerobias zerobias merged commit 00fa87a into master Apr 23, 2020
@delete-merged-branch delete-merged-branch bot deleted the feat/on-array branch April 23, 2020 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants