Last active
January 7, 2022 15:08
-
-
Save ulexxander/ca812d3e7f34159b1153e524d29e0fe7 to your computer and use it in GitHub Desktop.
Effector factory - Confirmation of some action
This file contains hidden or 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
import { createEvent, restore, sample } from "effector"; | |
export function createConfirmation<Require, Allow>() { | |
type Confirmed = { require: Require; allow: Allow }; | |
const require = createEvent<Require>(); | |
const $payload = restore(require, null); | |
const allow = createEvent<Allow>(); | |
const confirmed = createEvent<Confirmed>(); | |
sample({ | |
source: $payload, | |
clock: allow, | |
fn(require, allow) { | |
const payload: Confirmed = { require: require!, allow }; | |
return payload; | |
}, | |
target: confirmed, | |
}); | |
return { | |
require, | |
allow, | |
confirmed, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment