Subscribe on changes!

[FR] Make `withKeys` public

avatar
May 25th 2021

What problem does this feature solve?

Currently it's private:

image

It's really helpful for use cases like this:

<input
  v-model={password.value}
  type='password'
  onKeyup={withKeys(login, ['enter'])}
/>

Can we consider making it public? Given vue 3 is tree-shakeable, I don't see obvious drawbacks for this.

What does the proposed API look like?

withKeys being public.

avatar
May 25th 2021

If you are using JSX, you should just handle key events yourself. Exposing withKeys locks us into how it works and prevents potential future changes in internal implementations.

avatar
May 26th 2021

For anyone who comes to this, you can write a util function for this need.

export const withEnter = (fn: (...args: any[]) => any) => ({
  key,
}: {
  key: string
}): any => key === 'Enter' && fn()