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 support for trigger[] in store.on #328

Merged
merged 8 commits into from
Apr 23, 2020
Merged

Add support for trigger[] in store.on #328

merged 8 commits into from
Apr 23, 2020

Conversation

sergeysova
Copy link
Collaborator

@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)

@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.

None yet

2 participants