0.7.0 • Published 3 years ago

obso v0.7.0

Weekly downloads
263
License
MIT
Repository
github
Last release
3 years ago

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

ParamTypeDescription
eventNamestringthe 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

ParamTypeDescription
eventNamestringThe event name to watch. Omitting the name will catch all events.
handlerfunctionThe function to be called when eventName is emitted. Invocated with this set to emitter.
optionsobject
options.oncebooleanIf true, the handler will be invoked once then removed.

emitter.removeEventListener(eventName, handler)

Remove an event listener.

Kind: instance method of Emitter

ParamTypeDescription
eventNamestringthe event name
handlerfunctionthe event handler

emitter.once(eventName, handler)

Once.

Kind: instance method of Emitter

ParamTypeDescription
eventNamestringthe event name to watch
handlerfunctionthe 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.

0.7.0

3 years ago

0.6.0

4 years ago

0.5.1

4 years ago

0.5.0

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago