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

TypeError when Vue.bus.on (or other methods) is passed somewhere as an argument and only then executed #5

Closed
nicky1038 opened this issue Mar 15, 2019 · 3 comments

Comments

@nicky1038
Copy link

nicky1038 commented Mar 15, 2019

It's very useful to write the same logic for subscribing/unsubscribing to bus events in a separate function, and then call it passing Vue.bus.on or Vue.bus.off as an argument. But for now one cannot do this because of some this magic - a TypeError occurs.

Here's a minimal example to reproduce this issue:

Vue.use(VueBus);

function subscribe() {
	(function(s) {
		s('someevent', () => console.log('handled'));
	})(Vue.bus.on);
}

try {
	subscribe();
} catch(e) {
	alert(`IT'S A BUG! ${e.message}`);
}

Current workaround is to pass Vue.bus.on.bind(Vue.bus) instead of Vue.bus.on, but it's definitely not the way it should go.

@yangmingshan
Copy link
Owner

Sorry, I didn't check my inbox in time. I will fix it.

yangmingshan added a commit that referenced this issue Mar 23, 2019
@yangmingshan
Copy link
Owner

It should be good by now.

@nicky1038
Copy link
Author

I've tried it, now it works perfectly, thank you 👍

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

No branches or pull requests

2 participants