$ gnpm install obso
Make an object observable.
import Emitter from 'obso/index.mjs'
class Something extends Emitter {}
const something = new Something()
something.on('load', () => {
console.log('load event fired.')
})
Alias for on
.
Kind: instance property of Emitter
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 |
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 . |
[options] | object |
|
[options.once] | boolean |
If true , the handler will be invoked once then removed. |
Remove an event listener.
Kind: instance method of Emitter
Param | Type | Description |
---|---|---|
eventName | string |
the event name |
handler | function |
the event 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:
const Emitter = require('obso')
Within Node.js with ECMAScript Module support enabled:
import Emitter from 'obso/index.mjs'
Within an modern browser ECMAScript Module:
import Emitter from './node_modules/obso/index.mjs'
Old browser (adds window.Emitter
):
<script nomodule src="./node_modules/obso/dist/index.js"></script>
© 2018-21 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.
Copyright 2013 - present © cnpmjs.org | Home |