1.0.7 • Published 6 years ago

@nauma/eventemitter v1.0.7

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
6 years ago

EventEmitter

Using EventEmitter on node.js Size: 1.27 Kb 0 dependencies

install

npm i @nauma/eventemitter --save

using

require

const ee = require('@nauma/eventemitter')

create EventEmitter

let rest = new ee.EventEmitter()

add events

rest.on('todo', response => {
	console.log('in ->', response.data)
})

remove events

rest.removeEventListener('todo')

emit data

rest.emit('todo', { data: 'test-data' })

reply system

rest.on('todo', response => {
	console.log('in ->', response.data)
	response.reply({ text: 'hello world' })
})

rest.emit('todo', { data: 'test-data' })
  .then(data => {
    console.log('reply ->', data)
  })

EventEmitters group

const app = new ee.GroupEventEmitters()

const rest = new ee.EventEmitter('rest')
const database = new ee.EventEmitter('database')

app
  .add(rest)
  .add(database)
  // .add([rest, database])

app.get('rest')
	.on('todo', response => {
		console.log('in ->', response.data)
		response.reply({ lol: 'aruuuu' })
	})

app.get('rest')
	.emit('todo', { kek: 'lol' })
	.then(data => {
		console.log('reply ->', data)
	})

License

Apache 2.0

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago