From 6cb5a94162f4eeef28f3f7d457f2c5ed8276f720 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 21 Jan 2020 15:15:42 -0500 Subject: [PATCH 1/3] events api change --- active-rfcs/0000-events-api-change.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 active-rfcs/0000-events-api-change.md diff --git a/active-rfcs/0000-events-api-change.md b/active-rfcs/0000-events-api-change.md new file mode 100644 index 00000000..c7dce34d --- /dev/null +++ b/active-rfcs/0000-events-api-change.md @@ -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 easily be achieved by using an external library implementing the event emitter interface, for example [mitt](https://github.com/developit/mitt). + +These methods can also be easily provided in compatibility builds. From f1ba060da0d683498b1487d1efab1d8bc746d731 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 27 Feb 2020 10:48:27 -0500 Subject: [PATCH 2/3] Rename 0000-events-api-change.md to 0020-events-api-change.md --- .../{0000-events-api-change.md => 0020-events-api-change.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename active-rfcs/{0000-events-api-change.md => 0020-events-api-change.md} (100%) diff --git a/active-rfcs/0000-events-api-change.md b/active-rfcs/0020-events-api-change.md similarity index 100% rename from active-rfcs/0000-events-api-change.md rename to active-rfcs/0020-events-api-change.md From 59a13ad08cde4a32eded7c4603da9600fdaf1f02 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 27 Feb 2020 10:49:46 -0500 Subject: [PATCH 3/3] Update 0020-events-api-change.md --- active-rfcs/0020-events-api-change.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/active-rfcs/0020-events-api-change.md b/active-rfcs/0020-events-api-change.md index c7dce34d..871b2cc9 100644 --- a/active-rfcs/0020-events-api-change.md +++ b/active-rfcs/0020-events-api-change.md @@ -17,6 +17,6 @@ With Vue 2's API, `$emit` can be used to trigger event handlers declaratively at # 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 easily be achieved by using an external library implementing the event emitter interface, for example [mitt](https://github.com/developit/mitt). +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 easily provided in compatibility builds. +These methods can also be supported in compatibility builds.