Last active
October 25, 2022 08:37
-
-
Save lokhmakov/e6aab83b1d1b0561a1bd0350cf8ec84c to your computer and use it in GitHub Desktop.
effector - run effect once through event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const runQuery = createEffect({ | |
handler(props) { | |
console.log(props) | |
}, | |
}) | |
const createOnceEvent = to => { | |
const from = createEvent() | |
const unsubscribe = forward({from, to}) | |
from.watch(unsubscribe) | |
return from | |
} | |
const createOnceEffect = handler => { | |
const trigger = createEffect({handler}) | |
trigger.watch(() => trigger.use(() => {})) | |
return trigger | |
} | |
const runQueryOnce = createOnceEffect(runQuery) | |
runQueryOnce(1) | |
runQueryOnce(2) | |
runQueryOnce(3) | |
const doQueryOnce = createOnceEvent(runQuery) | |
doQueryOnce(1) | |
doQueryOnce(2) | |
doQueryOnce(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://share.effector.dev/D2K4vFZi