1.0.0 • Published 9 years ago

weak-error v1.0.0

Weekly downloads
12
License
MIT
Repository
github
Last release
9 years ago

weak-error Build Status

Weakmapped error event with a global capture hook

Install

$ npm install --save weak-error

Usage

var WeakError = require('weak-error')
var ErrorEvent = WeakError()
var obj = {}

// listen on only errors broadcasted on `obj`
ErrorEvent.listen(obj, onError)
// listen to all errors
WeakError.onError(onError)

ErrorEvent.broadcast({}, new Error('OH NO'))
//=> OH NO
//=> OH NO

function onError (err.message) {
  console.log(err.message)
}

API

WeakError() -> event

Constructs a weakmap-event. The event will work normally, but you can also listen on events globally.

WeakError.onError(listener) -> function

Listen globally on errors. Returns an unlisten function.

listener

Required
Type: function

A listener to call whenever any error is broadcasted, regardless of the key used.

License

MIT © Ben Drucker