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

fix event hook #471

Merged
merged 1 commit into from
Jan 12, 2018
Merged

fix event hook #471

merged 1 commit into from
Jan 12, 2018

Conversation

maxushuang
Copy link
Contributor

@maxushuang maxushuang commented Dec 14, 2017

Once an event, the event will not be removed. Because this event name become $$event in the off function.

if (!arguments.length) {
listeners = {}
} else {
const cbs = listeners[event]
if (cbs) {
if (!fn) {
if (!fn || cbs.length === 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxushuang Why are you making this change?

@posva
Copy link
Member

posva commented Dec 23, 2017

Hey sorry for the delay and thanks for the PR!
Could you explain a bit more what is not working as expected right now and is fixed by your PR?

@maxushuang
Copy link
Contributor Author

Hey, sorry, reply delay.
The vue-devtools source in src/backend/hook.js is below.

const hook = {
    once (event, fn) {
      event = '$' + event
      function on () {
        this.off(event, on)
        fn.apply(this, arguments)
      }
      ;(listeners[event] || (listeners[event] = [])).push(on)
    },
   off (event, fn) {
      event = '$' + event
      if (!arguments.length) {
        listeners = {}
      } else {
     ......
};
hook.once('event1', _ => {});

hook.emit('event1');

When hook emits event1, hook will call this.off(event, on). But, now, the event in this.off has becomes $event1, hook will add a '$' symbol again when call off function.
So hook will not off event correctly.

@michalsnik michalsnik added this to the 🎄Holiday Update milestone Jan 3, 2018
@yyx990803 yyx990803 merged commit dcc6189 into vuejs:master Jan 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants