Skip to content
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

Remove instance event API methods #118

Merged
merged 3 commits into from
Feb 27, 2020
Merged

Remove instance event API methods #118

merged 3 commits into from
Feb 27, 2020

Conversation

yyx990803
Copy link
Member

@yyx990803 yyx990803 commented Jan 21, 2020

Summary

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

Rendered

@yyx990803 yyx990803 added breaking change This RFC contains breaking changes or deprecations of old API. core 3.x This RFC only targets 3.0 and above labels Jan 21, 2020
@yyx990803
Copy link
Member Author

This RFC is now in final comments stage. An RFC in final comments stage means that:

The core team has reviewed the feedback and reached consensus about the general direction of the RFC and believe that this RFC is a worthwhile addition to the framework.
Final comments stage does not mean the RFC's design details are final - we may still tweak the details as we implement it and discover new technical insights or constraints. It may even be further adjusted based on user feedback after it lands in an alpha/beta release.
If no major objections with solid supporting arguments have been presented after a week, the RFC will be merged and become an active RFC.

@yyx990803 yyx990803 added the final comments This RFC is in final comments period label Feb 17, 2020
@yyx990803 yyx990803 merged commit d48576d into master Feb 27, 2020
@bodograumann
Copy link
Contributor

@yyx990803 Please update the link to the rendered rfc.

@blake-newman
Copy link
Member

@bodograumann I have updated.

@muthu32
Copy link

muthu32 commented Mar 17, 2020

Thanks for notifying about mitt.

@kouts
Copy link

kouts commented Apr 19, 2020

Sorry if this is an obvious question, in Vue.js 2 you could extend a component and listen to events that the parent (super) component emitted.
Example:

// Popup component
{
  ...
  name: 'Popup', 
  methods: {
    afterOpen () {
      this.$emit('after-open');
    }
  }
  ...
}

// CustomPopup extends Popup
const CustomPopup = {
  extends: Popup,
  ...
  created () {
    this.$on('after-open', function () {
       // do something here...
    });
  }
  ...
};

Is there any way to achieve the same now that $on will be removed?
Do component instances now have to depend on an external library that emits these events?

@mika76
Copy link

mika76 commented Apr 23, 2020

@kouts I need to know this too 😊

@yyx990803
Copy link
Member Author

@kouts @Mika86 yes, use a 3rd party lib. mitt is tiny.

@randriese
Copy link

randriese commented Jun 30, 2020

I'm a bit confused about this RFC... Not by the proposal to remove the instance methods and I have no objections on using Mitt, however, how would this play with 0030-emits-option as that states the usage of $emit?

@yyx990803 yyx990803 changed the title Events API Change Remove instance event API methods Jul 1, 2020
@yyx990803 yyx990803 added feature removal and removed final comments This RFC is in final comments period labels Jul 1, 2020
@bencodezen bencodezen mentioned this pull request Jul 6, 2020
25 tasks
@sinkersan
Copy link

Hello.
In Vue 2 we have option to subscribe on lifecycle hook like on events. This gives us ability to write something like this

export default {
  mounted() {
    const picker = new Pickaday({
      // ...
    });

    this.$once("hook:beforeDestroy", () => {
      picker.destroy();
    })
  }
};

Since in Vue 3 $once and $on are deprecated. Do we have an option to migrate this code and keep it in event based way?

@Kocal
Copy link

Kocal commented Nov 7, 2020

That's a good question, what is the new way to listen lifecycle hooks? Or it is now impossible?
We are stuck for adding Vue 3 support to Sentry Vue integration (getsentry/sentry-javascript#2925).

Friendly ping @posva / @yyx990803 ❤️

Thanks!

@sqal
Copy link

sqal commented Nov 7, 2020

@Kocal it's not documented but all lifecycle hooks receive component's instance as the second argument (source code) + there's getCurrentInstance api, so with that, you are able to do:

import { onMounted, onBeforeUnmount, getCurrentInstance, ref } from 'vue'

export default {
  name: 'Component',
  setup() {
    const instance = getCurrentInstance()
    const elRef = ref(null)

    onMounted(() => {
       const picker = new Pickaday(elRef.value, {});

      onBeforeUnmount(() => {
        picker.destroy()
      }, instance)
    })
  }
}

@Kocal
Copy link

Kocal commented Nov 7, 2020

Alright, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x This RFC only targets 3.0 and above breaking change This RFC contains breaking changes or deprecations of old API. core feature removal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants