-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat!: introduce controls
option
#362
Conversation
@vueuse/collaborators Would love to hear what you think about this, thanks! This is a breaking change aiming to be released to in v5.0. If you got any idea of refactoring/redesign other existing function, please let me know :) |
I think this will simplify usage for a majority of use cases for these functions. As for other functions that might make use of this I'll need to go through the list to see if I find any good candidates. Anyway really good work, I like this change 😄👍 |
I just checked |
I like this idea, this comment is only about how to select the controlled vs uncontrolled version. @antfu did you consider using a different function instead of passing the Internally it could still be implemented using this scheme in case it makes sense to reuse the implementation, but having a different function could give you the flexibility to simplify the uncontrolled versions of some of these functions (shaving some bytes and avoiding some extra objects in memory). For example, you could avoid the need for the const myTimestamp = useTimestamp()
const { timestamp, pause, resume } = usePausableTimestamp() (Note: Using Pausable because there are already some functions using this naming scheme, didn't though too much about it.) |
I love this idea! I will definitely apply this in my revisit of |
@matias-capeletto Thanks for the feedback! Actually, expose a new function for different signatures might be the more "right" way to do. But here is a few reasons I think it's better to go with
WDYT? |
Good points, totally fine with using About the first two points, you are right. I would say that is more about internal implementation, the docs could still remain the same because you could bundle the two functions in a single page (I think it is roughly the same to explain both ways). I think it is about trade-offs, as usual. Probably users that care a lot about performance are going to implement the timestamp themselves, and you can say that VueUse favors usability. About naming, I first went with The other problem I see is there is no way to tell Typescript that the two functions are related and that it should show them to the user together (Imagine if when you are using |
I like the idea! 👏 Like @matias-capeletto, I see VueUse as an usability first library that helps people to build stuff more easily without deep knowledge about some browser APIs for example. Therefore I don't have any objections against it. |
Since this version is going to introduce breaking changes, perhaps we could update the https://github.com/vueuse/vueuse/blob/main/packages/core/useRafFn/index.ts |
@jacobclevenger Thanks for spotting this. For sure we should remove the deprecated APIs. I don't think we would need |
Also looks like useAsyncState has a deprecated API that could be removed vueuse/packages/core/useAsyncState/index.ts Lines 82 to 83 in cc8656a
|
Motivation
Returning object allows functions have more flexibility and extensibility in the future. But for most of the time, we might just need one value without that many controls. The renaming in object destructure can be a bit verbose.
Proposed Solution
Introduce a new
controls
option that changes the return type. By default,controls
should be false make the usage more concise while also make it possible to have more controls when needed.It's well-typed in TypeScript, this should be able to minimize the confusion for both JS/TS users.
Affect functions
This is breaking changes for some functions. But we have different returning types (object/single ref) for different functions, this proposal also unified them to make the API more consistent.
API Changes
start
stop
function (previously deprecated)isActive
toisPending