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.

$emit poorly documented / breaks platform patterns

See original GitHub issue

Version

2.6.10

Reproduction link

https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events#Event_bubbling

It is largely a documentation issue / missing feature, so linking to the relevant JS Event spec on MDN.

Steps to reproduce

Call $emit(‘my-event’) on a component while listening for it on a grandparent component.

What is expected?

I expect to be able to fire an event that is able to say “this event should bubble until stopped” and likewise, fire an event that is not cancellable as per the JS specs.

What is actually happening?

There is no way to do this in Vue presently.


It has come to my attention that $emit does not allow for, nor does it, bubble events… At the very least, this deviation from the platform event spec should be clearly documented, as nobody working in JS ever expects they should have to implement bubbling manually when working with Javascript events (which $emit is alludes to being syntactic sugar for by claiming they are Custom Events . Ideally, $emit would be expanded to allow for bubbling to be manually controlled by the developer (As JS intends them to be done) by accepting something akin to the customEventInit object, this would include the added benefit of enabling ALL JS event specific features in the $emit method…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yyx990803commented, Apr 14, 2019

The docs never said custom events behave like native events. They are modeled after Node.js’ EventEmitter. The docs never claimed custom events are anything similar to native DOM events, in fact, it explicitly warns you that they are different concepts.

The deprecated option was $dispatch, which indeed bubbles, but it was removed in 2.0. In our experience bubbling events between components easily lead to code that is hard to understand because the event bubbling flow is very implicit.

0reactions
ktiedtcommented, Apr 14, 2019

@yyx990803 That is certainly more useful information, considering the docs call the feature Custom Events (which is the name in EcmaScript) it would be very useful to document this information and reference EventEmitters…

As Custom Events in Javascript are optionally able to bubble (by default they do not) so even if Vue opted to wrap the Native event system (Which makes a ton of sense for a predominantly client-side framework) by adding the EventInit object param, it would not change the default behavior in Vue and it would keep it consistent with the platform which is it built on top of.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Monolith Decomposition Patterns - InfoQ
Sam Newman shares some key principles and a number of patterns to use to incrementally decompose an existing system into microservices.
Read more >
Azure Stack Hub hotfix 1.2102.31.152 - Microsoft Learn
Shorten the "break-glass" tokens and make them human-readable. Fixed a bug related to physical disk health when repairing a node with SED drives....
Read more >
Chad Sanderson on LinkedIn: #dataengineering #data #sql | 45 ...
Sure, sometime you inherit a poorly documented mess, but that said a consistent root problem to address in every data shop is sprawl...
Read more >
Streams Concepts | Confluent Documentation
This allows Kafka Streams to update an aggregate value upon the out-of-order arrival of further records after the value was produced and emitted....
Read more >
What's New In Python 3.10 — Python 3.11.1 documentation
Patterns consist of sequences, mappings, primitive data types as well as class instances. Pattern matching enables programs to extract information from complex ...
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