Make an object observable.
npm install obso





Make an object observable.
``js`
import Emitter from 'obso/index.mjs'
class Something extends Emitter {}
const something = new Something()
something.on('load', () => {
console.log('load event fired.')
})
* obso
* Emitter ⏏
* .addEventListener
* .emit(eventName)
* [.on([eventName], handler, [options])](#module_obso--Emitter+on)
* .removeEventListener(eventName, handler)
* .once(eventName, handler)
#### emitter.addEventListener
Alias for on.
Kind: instance property of Emitter
#### emitter.emit(eventName)
Emit an event.
Kind: instance method of Emitter
| Param | Type | Description |
| --- | --- | --- |
| eventName | string | the event name to emit. |
| ...args | \* | args to pass to the event handler |
#### emitter.on([eventName], handler, [options])
Register an event listener.
Kind: instance method of Emitter
| Param | Type | Description |
| --- | --- | --- |
| [eventName] | string | The event name to watch. Omitting the name will catch all events. |
| handler | function | The function to be called when eventName is emitted. Invocated with this set to emitter. |true
| [options] | object | |
| [options.once] | boolean | If , the handler will be invoked once then removed. |
#### emitter.removeEventListener(eventName, handler)
Remove an event listener.
Kind: instance method of Emitter
| Param | Type | Description |
| --- | --- | --- |
| eventName | string | the event name |
| handler | function | the event handler |
#### emitter.once(eventName, handler)
Once.
Kind: instance method of Emitter
| Param | Type | Description |
| --- | --- | --- |
| eventName | string | the event name to watch |
| handler | function | the event handler |
This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.
Node.js:
`js`
const Emitter = require('obso')
Within Node.js with ECMAScript Module support enabled:
`js`
import Emitter from 'obso/index.mjs'
Within an modern browser ECMAScript Module:
`js`
import Emitter from './node_modules/obso/index.mjs'
Old browser (adds window.Emitter):
`html``
*
© 2018-21 Lloyd Brookes \<75pound@gmail.com\>. Documented by jsdoc-to-markdown.