-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Deprecations before v4 #715
Changes from all commits
28b66c6
b42b37f
b5be4ac
1de740e
7e3582b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
/** | ||
* @deprecated `State` is renamed to `UnknownState`, | ||
* `State` will be removed in next major | ||
*/ | ||
export type State = object | ||
|
||
export type UnknownState = object | ||
|
||
// types inspired by setState from React, see: | ||
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6c49e45842358ba59a508e13130791989911430d/types/react/v16/index.d.ts#L489-L495 | ||
/** | ||
* @deprecated Use the builtin `Partial<T>` instead of `PartialState<T>`. | ||
* Additionally turn on `--exactOptionalPropertyTypes` tsc flag. | ||
* `PartialState` will be removed in next major | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this has been troublesome and happy to drop it. |
||
*/ | ||
export type PartialState< | ||
T extends State, | ||
K1 extends keyof T = keyof T, | ||
|
@@ -10,10 +22,35 @@ export type PartialState< | |
> = | ||
| (Pick<T, K1> | Pick<T, K2> | Pick<T, K3> | Pick<T, K4> | T) | ||
| ((state: T) => Pick<T, K1> | Pick<T, K2> | Pick<T, K3> | Pick<T, K4> | T) | ||
|
||
/** | ||
* @deprecated Use `(t: T) => U` instead of `StateSelector<T, U>`. | ||
* `StateSelector` will be removed in next major. | ||
*/ | ||
export type StateSelector<T extends State, U> = (state: T) => U | ||
|
||
/** | ||
* @deprecated Use `(a: T, b: T) => boolean` instead of `EqualityChecker<T>. | ||
* `EqualityChecker` will be removed in next major. | ||
*/ | ||
export type EqualityChecker<T> = (state: T, newState: T) => boolean | ||
|
||
/** | ||
* @deprecated Use `(state: T, prevState: T) => void` instead of `StateListener<T>`. | ||
* `StateListener` will be removed in next major. | ||
*/ | ||
export type StateListener<T> = (state: T, previousState: T) => void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can try there three actually, and see if someone gets confused. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Did you thought about this and decided that if you want to keep them or not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep them. |
||
|
||
/** | ||
* @deprecated Use `(slice: T, prevSlice: T) => void` instead of `StateSliceListener<T>`. | ||
* `StateSliceListener` will be removed in next major. | ||
*/ | ||
export type StateSliceListener<T> = (slice: T, previousSlice: T) => void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think my plan was to drop this in #604. I don't know why I didn't. Let's drop this at least from vanilla.ts. |
||
|
||
/** | ||
* @deprecated Use `Store<T>['subscribe']` instead of `Subscribe<T>`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't dislike this, but people would get confused. Better to stay. Same for |
||
* `Subscribe` will be removed in next major. | ||
*/ | ||
export type Subscribe<T extends State> = { | ||
(listener: StateListener<T>): () => void | ||
/** | ||
|
@@ -26,6 +63,10 @@ export type Subscribe<T extends State> = { | |
): () => void | ||
} | ||
|
||
/** | ||
* @deprecated Use `Store<T>['setState']` instead of `SetState<T>` | ||
* `SetState` will be removed in next major. | ||
*/ | ||
export type SetState<T extends State> = { | ||
< | ||
K1 extends keyof T, | ||
|
@@ -37,21 +78,55 @@ export type SetState<T extends State> = { | |
replace?: boolean | ||
): void | ||
} | ||
|
||
/** | ||
* @deprecated Use `() => T` or `Store<T>['getState']` instead of `GetState<T>` | ||
* `GetState` will be removed in next major. | ||
*/ | ||
export type GetState<T extends State> = () => T | ||
|
||
/** | ||
* @deprecated Use `() => void` or `Store<UnknownState>['destroy']` instead of `Destroy`. | ||
* `Destroy` will be removed in next major. | ||
*/ | ||
export type Destroy = () => void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine to drop this. Not many people should be using. |
||
|
||
/** | ||
* @deprecated `StoreApi<T>` has been renamed to `Store<T>` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know you don't like this, but let's keep it. |
||
* `StoreApi` will be removed in next major. | ||
*/ | ||
export type StoreApi<T extends State> = { | ||
setState: SetState<T> | ||
getState: GetState<T> | ||
subscribe: Subscribe<T> | ||
destroy: Destroy | ||
} | ||
|
||
export type Store<T extends State> = { | ||
setState: SetState<T> | ||
getState: GetState<T> | ||
subscribe: Subscribe<T> | ||
destroy: Destroy | ||
} | ||
|
||
/** | ||
* @deprecated `StateCreator` has been renamed to `StoreInitializer`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep this. |
||
* `StateCreator` will be removed in next major. | ||
*/ | ||
export type StateCreator< | ||
T extends State, | ||
CustomSetState = SetState<T>, | ||
CustomGetState = GetState<T>, | ||
CustomStoreApi extends StoreApi<T> = StoreApi<T> | ||
> = (set: CustomSetState, get: CustomGetState, api: CustomStoreApi) => T | ||
|
||
export type StoreInitializer< | ||
T extends State, | ||
CustomSetState = SetState<T>, | ||
CustomGetState = GetState<T>, | ||
CustomStoreApi extends StoreApi<T> = StoreApi<T> | ||
> = (set: CustomSetState, get: CustomGetState, api: CustomStoreApi) => T | ||
|
||
function createStore< | ||
TState extends State, | ||
CustomSetState, | ||
|
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.
I would wanted to drop
State
entirely, and not even exportUnknownState
.But, this will probably be too big change, so let's keep it.
I would even want to make it
unknown
. If it were possible, we could consider dropping.