-
-
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
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 7e3582b:
|
will check this later. can you fix ci errors, meanwhile? |
Okay, I looked at the description (not the code yet), but this can't be accepted. Here are some overall comments:
I'm still open for suggestions about dropping and renaming types, but generally we need to consider more about backward compatibility. |
The |
I think we should make users, including TS beginners, adapt to the types instead of spoon-feeding them with types as trivial as
Okay haha I understand, we'll keep it backward compatible.
Yep that sounds good |
Added a comment in #725.
I'll review the suggestions again with the new approach in mind.
Please go ahead and create a PR, then v3.6.8 will be ready. |
Done #731 |
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.
Reviewed vanilla.ts. It turns out, I'd be more conservative.
@@ -1,6 +1,18 @@ | |||
/** | |||
* @deprecated `State` is renamed to `UnknownState`, | |||
* `State` will be removed in next major |
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 export UnknownState
.
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.
/** | ||
* @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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this has been troublesome and happy to drop it.
/** | ||
* @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 comment
The reason will be displayed to describe this comment to others. Learn more.
For StateSelector
, EqualityChecker
and StateListener
, I'm not sure what will happen. I guess many users use them. They might not be necessary nor best named, but not too confusing. So, for now I lean to keep them.
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 can try there three actually, and see if someone gets confused.
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 can try there three actually, and see if someone gets confused.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep them.
I saw some tweets and codesandboxes and know people use them.
If we were to remove those, it would be v5 (taking migration period longer like a few months to a year), which will not happen any time soon.
/** | ||
* @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 comment
The 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.
export type StateSliceListener<T> = (slice: T, previousSlice: T) => void | ||
|
||
/** | ||
* @deprecated Use `Store<T>['subscribe']` instead of `Subscribe<T>`. |
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 don't dislike this, but people would get confused. Better to stay. Same for SetState
and GetState
.
/** | ||
* @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 comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine to drop this. Not many people should be using.
export type Destroy = () => void | ||
|
||
/** | ||
* @deprecated `StoreApi<T>` has been renamed to `Store<T>` |
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 know you don't like this, but let's keep it.
} | ||
|
||
/** | ||
* @deprecated `StateCreator` has been renamed to `StoreInitializer`. |
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.
Let's keep this.
These types are rather simple to replace, so I don't think it would be troublesome to migrate, but I'm fine if you want to keep them. |
No, it's not about how troublesome they are to migrate. If people need to change something, people would hesitate. If they feel unhappy, they will leave. We are already planning many changes, so from your perspective, please think it as we should keep backward compatibility as much as possible. v3.6.x isn't nice for middleware typing. in this sense, middlware typing should be backward compatible with v3.5.x again as much as possible. |
Ha weird I thought the new branch renaming feature worked across forks xD — will reopen |
This PR is to be released as a minor which will contain deprecations that'll make the migration to the next major smoother. This is not to be merged yet, as #662 progresses this will get more commits if required, so this will be ready when #662 is ready.
I'm quite an idealist, I value correctness higher than non-breaking change, so changes are in alignment to that, they can always be negotiated later, I'm not the boss :)
Changes till now:
SetState<T>
toStore<T>['setState']
. It's best if derived types are actually derived. A type namedSetState<T>
doesn't tell what is it's relationship toStore<T>
or where did it came from. It's always good to only export the necessary types.EqualityChecker<T>
to(a: T, b: T) => boolean
andStateSelector<T, U>
to(state: T) => U
. The beauty of types is that you can tell their implementation by simply looking at them.StateSelector<T, U>
doesn't tell me anything about the implementation whereas a shorter(state: T) => U
does. Types should only be extracted if the name is more telling than it's definition or the definition is too long to write, egStore<T>
.StateCreator
toStoreInitializer
.Calling "store" as "storeApi" is like calling "todos" as "todosArray", "Tea" as "Tea beverage", "Devansh" as "Devansh Human". Good part is that this is not visible at a lot of places in the code. When using context, there's a
useStoreApi
so that is renamed touseStoreRef
(asuseStore
is already for reading the state).A more idealist and correct naming would have been calling
MyStoreContext.useStore()
as simplyMyStoreContext.use()
, andMyStoreContext.useStoreRef()
asMyStoreContext.useStore()
, but that's too radical change so I avoided it, let me know if you like it anyway.devtools({}, name)
todevtools({}, { name }
. Ability to pass the name directly is a rather unnecessary feature, more over expecting an object is consistent withpersist
. Good part is the documentation doesn't mention that you can directly pass the name so hopefully many users would not be using it.