obso
Make an object observable.
Last updated 4 years ago by 75lb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install obso 
SYNC missed versions from official npm registry.

view on npm npm module downloads Gihub repo dependents Gihub package dependents Build Status js-standard-style

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.')
})

obso

Emitter ⏏

Kind: Exported class

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.
[options] object
[options.once] boolean If true, 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

Load anywhere

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.

Current Tags

  • 0.7.0                                ...           latest (4 years ago)

11 Versions

  • 0.7.0                                ...           4 years ago
  • 0.6.0                                ...           5 years ago
  • 0.5.1                                ...           5 years ago
  • 0.5.0                                ...           5 years ago
  • 0.4.3                                ...           6 years ago
  • 0.4.2                                ...           6 years ago
  • 0.4.1                                ...           6 years ago
  • 0.4.0                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
  • 0.2.0                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (3)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |