From ecf1fdadbe1259c782250e2566d680a42fe696c3 Mon Sep 17 00:00:00 2001 From: Igor Kamyshev Date: Fri, 26 Jan 2024 16:00:48 +0100 Subject: [PATCH 1/2] Fix incorrect types of @@trigger in interval --- src/interval/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interval/index.ts b/src/interval/index.ts index 4964cc5a..b98eaadf 100644 --- a/src/interval/index.ts +++ b/src/interval/index.ts @@ -1,4 +1,4 @@ -import { Event, Store, createEvent, createStore, sample, attach, is } from 'effector'; +import { Event, EventCallable, Store, createEvent, createStore, sample, attach, is } from 'effector'; export function interval(config: { timeout: number | Store; @@ -146,8 +146,8 @@ function toStoreNumber(value: number | Store | unknown): Store { */ export type TriggerProtocol = { '@@trigger': () => { - setup: Event; - teardown: Event; + setup: EventCallable; + teardown: EventCallable; fired: Event | Event; }; }; From 7e8cf4e3f7cdb43413d20e56bfc0375885a2893a Mon Sep 17 00:00:00 2001 From: Igor Kamyshev Date: Fri, 26 Jan 2024 16:04:01 +0100 Subject: [PATCH 2/2] Fix incorrect logic --- src/interval/index.ts | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/interval/index.ts b/src/interval/index.ts index b98eaadf..6460661c 100644 --- a/src/interval/index.ts +++ b/src/interval/index.ts @@ -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(config: { timeout: number | Store; @@ -27,8 +36,21 @@ export function interval({ leading?: boolean; trailing?: boolean; }): { tick: Event; isRunning: Store } & TriggerProtocol { - const setup = (start ?? createEvent()) as Event; - const teardown = (stop ?? createEvent()) as Event; + 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);