Skip to content

Remove instance event API methods #118

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

Merged
merged 3 commits into from
Feb 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions active-rfcs/0020-events-api-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- Start Date: 2020-01-21
- Target Major Version: 3.x
- Reference Issues: https://github.com/vuejs/vue/issues/5443 https://github.com/vuejs/vue-next/issues/635
- Implementation PR: N/A

# Summary

Remove `$on`, `$off` and `$once` instance methods. Vue instances no longer implement the event emitter interface.

# Motivation

Vue 1.x implemented the component event system similar to that of AngularJS, with `$dispatch` and `$broadcast` where components in a tree can communicate by sending events up and down the tree.

In Vue 2, we removed `$dispatch` and `$broadcast` in favor of a more state-driven data flow (props down, events up).

With Vue 2's API, `$emit` can be used to trigger event handlers declaratively attached by a parent component (in templates or render functions), but can also be used to trigger handlers attached imperatively via the event emitter API (`$on`, `$off` and `$once`). This is in fact an overload: the full event emitter API isn't a part of the typical inter-component data-flow. They are rarely used, and there are really no strong reason for them to be exposed via component instances. This RFC therefore proposes to remove the `$on`, `$off` and `$once` instance methods.

# Adoption strategy

In Vue 2, the most common usage of the event emitter API is using an empty Vue instance as an event hub. This can be replaced by using an external library implementing the event emitter interface, for example [mitt](https://github.com/developit/mitt).

These methods can also be supported in compatibility builds.