Skip to content

Commit

Permalink
Fix incorrect logic
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Jan 26, 2024
1 parent ecf1fda commit 7e8cf4e
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/interval/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Event, EventCallable, Store, createEvent, createStore, sample, attach, is } from 'effector';
import {
Event,
EventCallable,
Store,
createEvent,
createStore,
sample,
attach,
is,
} from 'effector';

export function interval<S extends unknown, F extends unknown>(config: {
timeout: number | Store<number>;
Expand Down Expand Up @@ -27,8 +36,21 @@ export function interval<S extends unknown, F extends unknown>({
leading?: boolean;
trailing?: boolean;
}): { tick: Event<void>; isRunning: Store<boolean> } & TriggerProtocol {
const setup = (start ?? createEvent()) as Event<void>;
const teardown = (stop ?? createEvent()) as Event<void>;
const setup = createEvent();
if (start) {
sample({
clock: start,
target: setup,
});
}

const teardown = createEvent();
if (stop) {
sample({
clock: stop,
target: teardown,
});
}

const tick = createEvent();
const $isRunning = createStore(false);
Expand Down

0 comments on commit 7e8cf4e

Please sign in to comment.