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

3.4 updates #2625

Merged
merged 13 commits into from
Dec 29, 2023
Merged

3.4 updates #2625

merged 13 commits into from
Dec 29, 2023

Conversation

yyx990803
Copy link
Member

@yyx990803 yyx990803 commented Dec 26, 2023

Copy link

netlify bot commented Dec 26, 2023

Deploy Preview for vuejs ready!

Name Link
🔨 Latest commit 03d17cc
🔍 Latest deploy log https://app.netlify.com/sites/vuejs/deploys/658d26977f7fed0008c6f3a1
😎 Deploy Preview https://deploy-preview-2625--vuejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@yyx990803 yyx990803 mentioned this pull request Dec 27, 2023
3 tasks
@yyx990803 yyx990803 marked this pull request as ready for review December 27, 2023 05:09
@@ -52,15 +52,15 @@ Takes a getter function and returns a readonly reactive [ref](#ref) object for t
```ts
// read-only
function computed<T>(
getter: () => T,
getter: (oldValue: T | undefined) => T,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct that this is : T | undefined instead of ?: T, if I remember correctly there might be a TS compiler options so that | undefined means that it needs to explicitly pass a variable that can be undefined, instead of not passing a variable at all.
However, because this is a callback, it is not affected by this compile option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not passed by the user but provided by the framework, so the argument will always be present.

model.value = 'hello'

// declares "count" prop, consumed by parent via v-model:count
const count = defineModel('count')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some random thoughts

Is it possible to declare multiple models like that?

// v-model:count
const count = defineModel('count')
// v-model:x
const x = defineModel('x')

Or will this result in an error?
What happens if someone accidentally redeclared two times the same?

const count = defineModel('count')
const count2 = defineModel('count')

Should this be handled by a linter? Will there be a Vue runtime error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First case is supported. Second case will throw a compile-time error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add docs that different defineModels are supported and can be used that way? I think it is really common to have multiple v-model:* but it works differently as to defineProps or defineEmits where you pass multiple values at once, but for defineModel you suddenly need multiple calls.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already shown in the component v-model guide.

Like `defineProps` and `defineEmits`, `defineModel` can also receive type arguments to specify the types of the model value and the modifiers:

```ts
const modelValue = defineModel<string>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it that way? It feels like it behaves the opposite of ref 🤔
Here is an example:

first line: when I leave out the types at ref, it results in Ref<undefined> (legit to me 👍)
second line: when I explicitly use <boolean>, undefined is not a valid value (also legit to me 👍)

so I would assume that defineModel<string>() results in string and defineModel<string | undefined>() results in string | undefined and I don't need a required at all (or suddenly mix generics-TS and options object, where as e.g. defineProps explicitly forbids this mixing)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it accepts parent value via a prop, so it behaves like a prop (can be undefined unless explicitly required)

Copy link
Contributor

@Shinigami92 Shinigami92 Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see 🤔
should this be also documented, maybe with a :::tip? or might I have just oversee that?

@brc-dd brc-dd linked an issue Dec 28, 2023 that may be closed by this pull request
@yyx990803 yyx990803 merged commit 904e851 into main Dec 29, 2023
5 checks passed
@yyx990803 yyx990803 deleted the 3.4 branch December 29, 2023 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing search result for defineModel
4 participants