Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bv-ui-core

Package Overview
Dependencies
Maintainers
5
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bv-ui-core - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

25

lib/evented/index.js

@@ -22,2 +22,19 @@ /* eslint-disable */

/**
* By default, we should simply log the error to the console.
*/
function defaultErrorHandler(e) {
global.console.error(e);
}
/**
* Initialize a custom error handler for this instance, which may decide to log or even re-throw the error.
*
* @param {Function} fn - the custom callback to be invoked whenever an error is
* detected as the result of a trigger event
*/
function setErrorHandler(fn) {
this.eventErrorHandler = fn;
}
function bind(event, fn) {

@@ -82,3 +99,8 @@ var i, part;

}
catch (e) {}
catch (e) {
(this.eventErrorHandler || defaultErrorHandler).call(this, e, {
event: event,
data: args
});
}
}

@@ -111,2 +133,3 @@ return this;

this.one = this.once = one;
this.setErrorHandler = setErrorHandler;

@@ -113,0 +136,0 @@ return this;

@@ -24,2 +24,20 @@ # evented

By default, any errors thrown from an event listener are caught and simply logged to the console.
An alternate behavior can be specified by providing an event handler:
```js
var model = new Model({});
model.setErrorHandler(function(error, trigger) {
// The following parameters are available to this function:
// - error : the value that was thrown, typically an instance of Error
// - trigger.event : the name of the event passed to trigger()
// - trigger.data : an array containing the additional arguments passed to trigger()
// - this : the instance on which trigger() was invoked
});
// If you prefer for errors to be thrown from trigger(), then use:
model.setErrorHandler(function(error) { throw error; });
```
[1]: https://github.com/mkuklis/asEvented

2

lib/global/index.js

@@ -10,4 +10,4 @@ /**

if (typeof globalThis !== 'undefined') { return globalThis; }
if (typeof window !== 'undefined') { return window; }
if (typeof self !== 'undefined') { return self; }
if (typeof window !== 'undefined') { return window; }
if (typeof global !== 'undefined') { return global; }

@@ -14,0 +14,0 @@ throw new Error('unable to locate global object');

{
"name": "bv-ui-core",
"version": "2.1.1",
"version": "2.2.0",
"license": "Apache 2.0",

@@ -5,0 +5,0 @@ "description": "Bazaarvoice UI-related JavaScript",

@@ -29,2 +29,32 @@ /**

it('invokes an errorHandler function correctly', function () {
function M () {}
evented.call(M.prototype);
var m = new M();
// Ensure that errors escaping from listeners are caught
var error = new Error('test error 1');
m.on('test_event', function () {
throw error;
});
m.trigger('test_event'); // should NOT throw
// Ensure that errors are provided to custom error handler
error = new Error('test error 2');
var spy = sinon.spy();
m.setErrorHandler(spy);
m.trigger('test_event');
expect(spy).to.have.been.calledWith(error, sinon.match.has('event', 'test_event'));
// Ensure that errors can be rethrown from custom error handler
error = new Error('test error 3');
m.setErrorHandler(function (theError) {
throw theError;
});
expect(function () {
m.trigger('test_event');
}).to.throw(error);
})
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc