Skip to content

Instantly share code, notes, and snippets.

@ulexxander
Last active January 7, 2022 15:08
Show Gist options
  • Save ulexxander/ca812d3e7f34159b1153e524d29e0fe7 to your computer and use it in GitHub Desktop.
Save ulexxander/ca812d3e7f34159b1153e524d29e0fe7 to your computer and use it in GitHub Desktop.
Effector factory - Confirmation of some action
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