question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modifier to propagate/forward events to parent

See original GitHub issue

What problem does this feature solve?

Currently, and as far as I know, if we want to propagate an event fired by a child component to the parent (the child’s grandparent) we need to $emit the event again, and we need to pass all the arguments one more time. This can become a problem, for example, if the event has a variable number of arguments because we need to specify them manually or pass the whole array as a new argument.

The current way would be something like

@blur="$emit('blur')"
@create="$emit('create', arguments[0])"
@input="$emit('input', arguments[0], arguments[1])"

What does the proposed API look like?

@blur.propagate
@create.propagate
@input.propagate

And if we want to both handle the event and propagate it to the parent, we would use

@input.propagate="someFunction"

EDIT: Maybe since .propagate may be confused with the function .stopPropagation(), a better term could be simply .emit

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:73
  • Comments:18

github_iconTop GitHub Comments

6reactions
Vontuscommented, Jan 17, 2019

@laander That solves the issue with the arguments, but I think a modifier to let Vue do it would be a nice addition.

I think this modifier can be specially useful for wrapper components that need to emit most events they receive from their child component.

5reactions
lopugitcommented, Sep 15, 2019

nice!!! OPEN SOURCE FTW

Read more comments on GitHub >

github_iconTop Results From Across the Web

qt - How do I propagate a mousePressEvent() to a group of ...
Calling accept() in mousePressEvent will prevent the event from being propagated to the child object. I believe this is true, but the parent...
Read more >
List of Compose modifiers - Jetpack - Android Developers
Creates a modifier that controls the drawing order for the children of the same layout parent. Focus. Scope: Any. Modifier ...
Read more >
How to raise base class events in derived classes - C# ...
The following simple example shows the standard way to declare events in a base class so that they can also be raised from...
Read more >
Events / Event forwarding • Svelte Tutorial
Unlike DOM events, component events don't bubble. If you want to listen to an event on some deeply nested component, the intermediate components...
Read more >
Emit an event from a child to parent component in Angular 9
When the event is emitted upward to the parent component, the parentEventHandlerFunction function (which we will code next) will be called. Notice the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found