Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce UnitTargetable, EventCallable and StoreWritable #966

Merged
merged 37 commits into from Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f5229d0
Introduce EventCallable<T> and StoreWritable<T>
sergeysova Jul 6, 2023
8c2ee22
.reinit should be available only on StoreWritable
sergeysova Jul 6, 2023
700b5e8
use EventCallable for effector-react
sergeysova Jul 6, 2023
1810b4f
use EventCallable for effector-solid
sergeysova Jul 6, 2023
fccf281
use EventCallable for forest
sergeysova Jul 6, 2023
dd63eea
update type snapshot tests for sample
sergeysova Jul 6, 2023
af742ed
update type snapshot tests for filterSample
sergeysova Jul 6, 2023
6caa940
update type shapshot tests for generated tests of sample
sergeysova Jul 6, 2023
297d38f
fix Target type for sample
sergeysova Jul 6, 2023
6a09cd3
restore of the shape should produce StoreWritable
sergeysova Jul 6, 2023
13d7770
.reset should be only on StoreWritable
sergeysova Jul 6, 2023
d390fe2
createApi should return EventCallable
sergeysova Jul 6, 2023
0a67b61
update test snapshots for types
sergeysova Jul 6, 2023
72f51cf
Introduce UnitTargetable as an extension of Unit
AlexandrHoroshih Sep 10, 2023
ad64041
Make virtual property less weird
AlexandrHoroshih Sep 10, 2023
ad079b2
Do not require UnitTarget for store.on - any unit should fit
AlexandrHoroshih Sep 10, 2023
f11eee2
Make ts guard against incompatible store types
AlexandrHoroshih Sep 10, 2023
b3b0f0e
Add type test updates with fixed cases
AlexandrHoroshih Sep 10, 2023
3fb1a4a
Bump TS to 5.2.2
AlexandrHoroshih Sep 10, 2023
e5f0102
Update type snapshots after ts 5
AlexandrHoroshih Sep 10, 2023
4257f07
Update implicit combine snapshots
AlexandrHoroshih Sep 10, 2023
ad0567e
Update snapshots
AlexandrHoroshih Sep 18, 2023
2600985
Delete `forward` tests with generic usage
AlexandrHoroshih Sep 18, 2023
b909c33
Revert "Delete `forward` tests with generic usage"
AlexandrHoroshih Sep 18, 2023
98a896e
Merge branch 'release/v23' into introduce-unit-targetable
AlexandrHoroshih Sep 21, 2023
4abe19e
Merge branch 'release/v23' into introduce-unit-targetable
AlexandrHoroshih Sep 22, 2023
bf3a848
Update forward types
AlexandrHoroshih Sep 22, 2023
ebf05ab
Update sample type snapshots after merge
AlexandrHoroshih Sep 22, 2023
77ea3c7
Fix forward types
AlexandrHoroshih Sep 22, 2023
3b867c6
Update snapshots on breaking generic tests
AlexandrHoroshih Sep 22, 2023
9efda03
Fix tests for fork and effect
AlexandrHoroshih Sep 22, 2023
0ec232f
Better error messages in cases of unsafe store type widening
AlexandrHoroshih Sep 22, 2023
28303b7
Update snapshots
AlexandrHoroshih Sep 22, 2023
f661c04
Fix Event assertions in types tests
AlexandrHoroshih Sep 22, 2023
4353c76
Fix Store assertions in type tests
AlexandrHoroshih Sep 22, 2023
b4282b4
Add type-tests to explicitly forbid derived units in sample target
AlexandrHoroshih Sep 23, 2023
0b22edf
Introduce better error message for derived units in target
AlexandrHoroshih Sep 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -112,7 +112,7 @@
"solid-testing-library": "^0.3.0",
"terser": "^5.6.1",
"ts-node": "^10.0.0",
"typescript": "4.9.4",
"typescript": "5.2.2",
"use-sync-external-store": "^1.0.0",
"viz.js": "^2.1.2",
"vue": "^2.6.12",
Expand Down
29 changes: 13 additions & 16 deletions packages/effector-react/index.d.ts
@@ -1,5 +1,5 @@
import React from 'react'
import {Store, Event, Effect, Domain, Scope} from 'effector'
import {Store, Event, Effect, Domain, Scope, EventCallable} from 'effector'

export const Provider: React.Provider<Scope>

Expand Down Expand Up @@ -135,14 +135,14 @@ export function createStoreConsumer<State>(
* @deprecated use useUnit hook instead
*/
export function useEvent(
event: Event<void>,
event: EventCallable<void>,
opts?: {forceScope?: boolean},
): () => void
/**
* @deprecated use useUnit hook instead
*/
export function useEvent<T>(
event: Event<T>,
event: EventCallable<T>,
opts?: {forceScope?: boolean},
): (payload: T) => T
/**
Expand All @@ -159,14 +159,11 @@ export function useEvent<T, R>(
fx: Effect<T, R, any>,
opts?: {forceScope?: boolean},
): (payload: T) => Promise<R>
/**
* @deprecated use useUnit hook instead
*/
export function useEvent<List extends (Event<any> | Effect<any, any>)[]>(
export function useEvent<List extends (EventCallable<any> | Effect<any, any>)[]>(
list: [...List],
opts?: {forceScope?: boolean},
): {
[Key in keyof List]: List[Key] extends Event<infer T>
[Key in keyof List]: List[Key] extends EventCallable<infer T>
? (payload: T) => T
: List[Key] extends Effect<infer P, infer D, any>
? (payload: P) => Promise<D>
Expand All @@ -176,12 +173,12 @@ export function useEvent<List extends (Event<any> | Effect<any, any>)[]>(
* @deprecated use useUnit hook instead
*/
export function useEvent<
Shape extends Record<string, Event<any> | Effect<any, any, any>>,
Shape extends Record<string, EventCallable<any> | Effect<any, any, any>>,
>(
shape: Shape,
opts?: {forceScope?: boolean},
): {
[Key in keyof Shape]: Shape[Key] extends Event<infer T>
[Key in keyof Shape]: Shape[Key] extends EventCallable<infer T>
? (payload: T) => T
: Shape[Key] extends Effect<infer P, infer D, any>
? (payload: P) => Promise<D>
Expand All @@ -199,11 +196,11 @@ export function useUnit<State>(
opts?: {forceScope?: boolean},
): State
export function useUnit(
event: Event<void>,
event: EventCallable<void>,
opts?: {forceScope?: boolean},
): () => void
export function useUnit<T>(
event: Event<T>,
event: EventCallable<T>,
opts?: {forceScope?: boolean},
): (payload: T) => T
export function useUnit<R>(
Expand All @@ -215,12 +212,12 @@ export function useUnit<T, R>(
opts?: {forceScope?: boolean},
): (payload: T) => Promise<R>
export function useUnit<
List extends (Event<any> | Effect<any, any> | Store<any>)[],
List extends (EventCallable<any> | Effect<any, any> | Store<any>)[],
>(
list: [...List],
opts?: {forceScope?: boolean},
): {
[Key in keyof List]: List[Key] extends Event<infer T>
[Key in keyof List]: List[Key] extends EventCallable<infer T>
? Equal<T, void> extends true
? () => void
: (payload: T) => T
Expand All @@ -233,12 +230,12 @@ export function useUnit<
: never
}
export function useUnit<
Shape extends Record<string, Event<any> | Effect<any, any, any> | Store<any>>,
Shape extends Record<string, EventCallable<any> | Effect<any, any, any> | Store<any>>,
>(
shape: Shape | {'@@unitShape': () => Shape},
opts?: {forceScope?: boolean},
): {
[Key in keyof Shape]: Shape[Key] extends Event<infer T>
[Key in keyof Shape]: Shape[Key] extends EventCallable<infer T>
? Equal<T, void> extends true
? () => void
: (payload: T) => T
Expand Down
14 changes: 7 additions & 7 deletions packages/effector-solid/index.d.ts
@@ -1,4 +1,4 @@
import {Store, Event, Effect, Domain, Scope} from 'effector'
import {Store, Event, Effect, Domain, Scope, EventCallable} from 'effector'
import {Accessor, Component, FlowComponent} from 'solid-js'

export const Provider: FlowComponent<{
Expand Down Expand Up @@ -52,11 +52,11 @@ export function useUnit<State>(
opts?: {forceScope?: boolean},
): Accessor<State>
export function useUnit(
event: Event<void>,
event: EventCallable<void>,
opts?: {forceScope?: boolean},
): () => void
export function useUnit<T>(
event: Event<T>,
event: EventCallable<T>,
opts?: {forceScope?: boolean},
): (payload: T) => T
export function useUnit<R>(
Expand All @@ -68,12 +68,12 @@ export function useUnit<T, R>(
opts?: {forceScope?: boolean},
): (payload: T) => Promise<R>
export function useUnit<
List extends (Event<any> | Effect<any, any> | Store<any>)[],
List extends (EventCallable<any> | Effect<any, any> | Store<any>)[],
>(
list: [...List],
opts?: {forceScope?: boolean},
): {
[Key in keyof List]: List[Key] extends Event<infer T>
[Key in keyof List]: List[Key] extends EventCallable<infer T>
? Equal<T, void> extends true
? () => void
: (payload: T) => T
Expand All @@ -86,12 +86,12 @@ export function useUnit<
: never
}
export function useUnit<
Shape extends Record<string, Event<any> | Effect<any, any, any> | Store<any>>,
Shape extends Record<string, EventCallable<any> | Effect<any, any, any> | Store<any>>,
>(
shape: Shape | {'@@unitShape': () => Shape},
opts?: {forceScope?: boolean},
): {
[Key in keyof Shape]: Shape[Key] extends Event<infer T>
[Key in keyof Shape]: Shape[Key] extends EventCallable<infer T>
? Equal<T, void> extends true
? () => void
: (payload: T) => T
Expand Down