-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sova <[email protected]> Co-authored-by: Viktor <[email protected]>
- Loading branch information
1 parent
f67cde3
commit 9ddcb90
Showing
5 changed files
with
152 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
import { Unit, Store } from 'effector'; | ||
import { createEvent } from 'effector'; | ||
|
||
export function reset({ | ||
clock, | ||
target, | ||
}: { | ||
clock: Unit<any> | Array<Unit<any>>; | ||
import type { Event, Unit, Store } from 'effector'; | ||
|
||
type Params = { | ||
clock?: Unit<any> | Array<Unit<any>>; | ||
target: Store<any> | Array<Store<any>>; | ||
}): void { | ||
}; | ||
|
||
export function reset(config: Required<Params>): void; | ||
export function reset(config: Pick<Params, 'target'>): Event<void>; | ||
|
||
export function reset({ clock, target }: Params) { | ||
const targets = Array.isArray(target) ? target : [target]; | ||
const clocks = Array.isArray(clock) ? clock : [clock]; | ||
const clocks = Array.isArray(clock) ? clock : [clock ?? createEvent()]; | ||
targets.forEach((target) => { | ||
target.reset(clocks); | ||
}); | ||
|
||
return clock === undefined ? clocks[0] : undefined; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { expectType } from 'tsd'; | ||
import { createEvent, createEffect, createStore } from 'effector'; | ||
import { reset } from '../src/reset'; | ||
|
||
import type { Event } from 'effector'; | ||
|
||
// With clock in params | ||
{ | ||
const event = createEvent(); | ||
const $store = createStore(''); | ||
const $clock = createStore(''); | ||
const fx = createEffect(); | ||
|
||
expectType<void>(reset({ clock: event, target: $store })); | ||
expectType<void>(reset({ clock: event, target: [$store] })); | ||
expectType<void>(reset({ clock: [event], target: [$store] })); | ||
expectType<void>(reset({ clock: [event], target: $store })); | ||
|
||
expectType<void>(reset({ clock: fx, target: $store })); | ||
expectType<void>(reset({ clock: fx, target: [$store] })); | ||
expectType<void>(reset({ clock: [fx], target: [$store] })); | ||
expectType<void>(reset({ clock: [fx], target: $store })); | ||
|
||
expectType<void>(reset({ clock: $clock, target: $store })); | ||
expectType<void>(reset({ clock: $clock, target: [$store] })); | ||
expectType<void>(reset({ clock: [$clock], target: [$store] })); | ||
expectType<void>(reset({ clock: [$clock], target: $store })); | ||
|
||
expectType<void>(reset({ clock: [event, $clock, fx], target: $store })); | ||
expectType<void>(reset({ clock: [event, $clock, fx], target: [$store] })); | ||
} | ||
|
||
// Without clock in params | ||
{ | ||
const $store = createStore(''); | ||
|
||
expectType<Event<void>>(reset({ target: $store })); | ||
expectType<Event<void>>(reset({ target: [$store] })); | ||
} |
9ddcb90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚛 size-compare report
Comparing f67cde32...9ddcb906