1.0.3 • Published 6 years ago
npm-events v1.0.3
Events
Events which are used to pass the data between child components to any parent components. This plugin which can be included in any kind of frameworks like react,vue,angular js..
Build Setup
#Events - plugin
#Example using vuejs
It should be included in a main.js and create as many number of window object (event-name), so that user can create multiple event emitter from child to any parent in the DOM. This plugin Emitter.js which can be included in any frameworks like angular,react,vue js..
#main.js
import Vue from 'vue'
var Emitter = require('npm-events')
window.events = {}
window.anotherEvent = {}
Emitter(events)
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})
#event-types
# emit an event
events.emit('event-name', {
})
#Listen to that event whenever emitted
events.on('event-name',() => {
})
#remove the particular event
events.off('event-name')
#remove all events
events.off()
#event is called only once and it is automatically get removed
events.once('event-name',() => {
})
#n - number of events
anotherEvent.emit('event-name',{})
anotherEvent.on('event-name',() => {
})
anotherEvent.off('event-name')
anotherEvent.once('event-name',() => {
})