diff --git a/src/interval/index.ts b/src/interval/index.ts index dd85cfd5..7318d711 100644 --- a/src/interval/index.ts +++ b/src/interval/index.ts @@ -131,11 +131,11 @@ export function interval({ return { tick, isRunning: $isRunning, - '@@trigger': { + '@@trigger': () => ({ setup, teardown, fired: tick, - }, + }), }; } @@ -153,6 +153,10 @@ function toStoreNumber(value: number | Store | unknown): Store { /** * @see {@link https://withease.pages.dev/protocols/trigger.html} */ -type TriggerProtocol = { - '@@trigger': { fired: Event; setup: Event; teardown: Event }; +export type TriggerProtocol = { + '@@trigger': () => { + setup: Event; + teardown: Event; + fired: Event | Event; + }; }; diff --git a/src/interval/interval.fork.test.ts b/src/interval/interval.fork.test.ts index 33f1e9a0..06007c5a 100644 --- a/src/interval/interval.fork.test.ts +++ b/src/interval/interval.fork.test.ts @@ -107,22 +107,22 @@ test('does not leaves unresolved timeout effect, if stopped', async () => { describe('@@trigger', () => { test('fire tick on start and stop after teardown', async () => { const listener = jest.fn(); - const intervalTrigger = interval({ timeout: 1 }); + const intervalTrigger = interval({ timeout: 1 })['@@trigger'](); const scope = fork(); const unwatch = createWatch({ - unit: intervalTrigger['@@trigger'].fired, + unit: intervalTrigger.fired, fn: listener, scope, }); - allSettled(intervalTrigger['@@trigger'].setup, { scope }); + allSettled(intervalTrigger.setup, { scope }); await wait(1); expect(listener).toBeCalledTimes(1); - await allSettled(intervalTrigger['@@trigger'].teardown, { scope }); + await allSettled(intervalTrigger.teardown, { scope }); await wait(10); expect(listener).toBeCalledTimes(1);