/vuemit

The smallest Vue.js events handler.

Primary LanguageJavaScriptMIT LicenseMIT

Vuemit

Demo Version Downloads License

Vuemit is a tiny library to work with events on Vue.js. Its aim is to keeping simple the fact of sharing information between two o more components.

Requirements

You will have to install Vue, as so:

npm install vue --save

Gettings started

You will have to require this library within your entry point or your bootstrap file, as so:

window.Vuemit = require('vuemit');

This process will create a Vuemit variable as globally for you to use it within any files needed.

See Demo

After importing it, you will be able to fire, listen, listen once, remove, remove listeners from a particular event or remove all listeners.

The explanation for each method is listed below:


Fire an event: To fire an event you will have to pass two parameters to the method, being the first one the event name, and the second one the required data if needed. As so:

Vuemit.fire('setAddress', {name: 'gocanto'});    

See this demo for more information.

Listen for event: To listen to an event you will have to be able to know the name of the fired event and the callback that will handle the information according to the event been fired. As so:

Vuemit.listen('setAddress', callback);

See this demo for more information.

Listen once: This option will listen for an event and trigger only once, and will then be removed. As so:

Vuemit.listenOnce('setAddress', callback);

Remove: Removes listeners for a given event and callback. As so:

Vuemit.remove('setAddress', callback);

Remove listeners from: Removes all listeners for a given event. As so:

Vuemit.removeListenersFrom('setAddress');

Remove all: Removes all event listeners. As so:

Vuemit.removeAll();

Contributing

Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.

License

The MIT License (MIT). Please see License File for more information.

How can I thank you?

Why not star the github repo? Why not share the link for this repository on Twitter? Spread the word!

Don't forget to follow me on twitter!

Thanks!

Gustavo Ocanto. gustavoocanto@gmail.com