-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
feat: handle nested defineEmits #13262
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
base: minor
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Can you provide more context? What was |
@Justineo My request is not about Neglible: Also I don't like the empty assignment in the compiled code As for I prefer individual event functions to keep the usage symetrical between the publishing side and the consumer side: ComponentA: const { onValidChanged } = splitEmitFunctions(defineEmits<{ onValidChanged: [valid: boolean] }>());
// const emit = defineEmits<{ onValidChanged: [valid: boolean] }>();
// const onValidChanged: (valid : boolean) => void = (value) => emit('onValidChanged ', value);
watch(valid, (value) -> onValidChanged(value)) ComponentB: <script setup lang="ts">
const onValidChanged: (valid: boolean) => void = (value) => continue.disabled = value;
</script>
<template>
<ComponentA @onValidChanged="onValidChanged" />
</template> So that: ComponentA's ComponentA: const { onValidChanged } = splitEmitFunctions(defineEmits<{ onValidChanged: OnValueChanged }>()); ComponentB: <script setup lang="ts">
const onValidChanged: OnValueChanged = (value) => continue.disabled = value;
</script> But you could also use it for different usecases such as simplified debug logging: function logToConsole<T>(emit: T): T {
return (...args) => {
console.log("Event", ...args);
emit(...args);
}
} const emit = logToConsole(defineEmits<{ onValidChanged: [valid: boolean] }>());
watch(valid, (value) -> emit('onValidChanged ', value)) |
I'm not sure whether this is a fix or a feature.
This PR allows calling
defineEmits
as an argument of another method.My Usecase
splitEmitFunctions
definitionWithout this patch, you have to use the following code:
poluting the scope with the
emit
variable, that shouldn't be used after this.