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

dispatchr

Package Overview
Dependencies
Maintainers
4
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dispatchr - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

7

CHANGELOG.md
# Change Log
## 1.1.0
### Enhancement
* [#496] Allow error handler to be used instead of throwing. [Docs](https://github.com/yahoo/fluxible/blob/master/packages/dispatchr/docs/dispatchr.md#error-handling).
## 1.0.3

@@ -8,2 +14,1 @@

* [#479] Update eventemitter3 to 2.0.0, by @stanback

@@ -14,2 +14,3 @@ /**

* @param {Array} options.stores Array of stores to register
* @param {Function} options.errorHandler Called when an error occurrs. Allows user to handle/throw the error.
* @constructor

@@ -23,2 +24,3 @@ */

this.handlers[DEFAULT] = [];
this.errorHandler = options.errorHandler;
this.hasWarnedAboutNameProperty = false;

@@ -46,7 +48,9 @@ options.stores.forEach(function (store) {

if ('function' !== typeof store) {
throw new Error('registerStore requires a constructor as first parameter');
var message = 'registerStore requires a constructor as first parameter';
return this._throwOrCallErrorHandler(message, 'REGISTER_STORE_NO_CONSTRUCTOR');
}
var storeName = this.getStoreName(store);
if (!storeName) {
throw new Error('Store is required to have a `storeName` property.');
var message = 'Store is required to have a `storeName` property.';
return this._throwOrCallErrorHandler(message, 'REGISTER_STORE_NO_STORENAME');
}

@@ -58,4 +62,5 @@ if (this.stores[storeName]) {

}
throw new Error('Store with name `' + storeName + '` has already been registered. ' +
'Make sure you do not have multiple copies of the store installed.');
var message = 'Store with name `' + storeName + '` has already been registered. ' +
'Make sure you do not have multiple copies of the store installed.';
return this._throwOrCallErrorHandler(message, 'REGISTER_STORE_DUPLICATE_REGISTERED');
}

@@ -143,2 +148,27 @@ this.stores[storeName] = store;

/**
* Executes `errorHandler` if registered, otherwise will throw an error
* @method _throwOrCallErrorHandler
* @private
* @static
* @param {String} message Error message to use for throw
* @param {String} [type=DISPATCHER_ERROR] Type of error generated
* @param {Object} [context] DispatcherContext object
* @param {Object} [meta] Additional information to pass to the error handler. Message
will automatically be passed into the meta object.
* @throws {Error} if `errorHandler` is not defined
* @returns {void}
*/
Dispatcher.prototype._throwOrCallErrorHandler = function throwOrCallErrorHandler(message, type, context, meta) {
if (this.errorHandler) {
this.errorHandler({
message: message,
type: type || 'DISPATCHER_ERROR',
meta: meta
}, context);
} else {
throw new Error(message);
}
};
module.exports = {

@@ -145,0 +175,0 @@ createDispatcher: function (options) {

@@ -17,2 +17,3 @@ /**

function DispatcherContext (dispatcher, context) {
this.context = context;
this.dispatcher = dispatcher;

@@ -41,3 +42,7 @@ this.storeInstances = {};

if (!Store) {
throw new Error('Store ' + storeName + ' was not registered.');
var message = 'Store ' + storeName + ' was not registered.';
var meta = {
storeName: storeName
};
return this.dispatcher._throwOrCallErrorHandler(message, 'STORE_UNREGISTERED', this.context, meta);
}

@@ -65,6 +70,12 @@ this.storeInstances[storeName] = new (this.dispatcher.stores[storeName])(this.dispatcherInterface);

if (!actionName) {
throw new Error('actionName parameter `' + actionName + '` is invalid.');
var message = 'actionName parameter `' + actionName + '` is invalid.';
return this.dispatcher._throwOrCallErrorHandler(message, 'DISPATCH_INVALID_ACTIONNAME', this.context);
}
if (this.currentAction) {
throw new Error('Cannot call dispatch while another dispatch is executing. Attempted to execute \'' + actionName + '\' but \'' + this.currentAction.name + '\' is already executing.');
var message = 'Cannot call dispatch while another dispatch is executing. Attempted to execute \'' + actionName + '\' but \'' + this.currentAction.name + '\' is already executing.';
var meta = {
actionName: actionName,
payload: payload
};
return this.dispatcher._throwOrCallErrorHandler(message, 'DISPATCH_EXECUTING', this.context, meta);
}

@@ -94,3 +105,7 @@ var actionHandlers = this.dispatcher.handlers[actionName] || [],

if (!storeInstance[store.handler]) {
throw new Error(store.name + ' does not have a method called ' + store.handler);
var message = store.name + ' does not have a method called ' + store.handler;
var meta = {
store: store
};
return this.dispatcher._throwOrCallErrorHandler(message, 'DISPATCH_INVALID_STORE_METHOD', this.context, meta);
}

@@ -156,3 +171,7 @@ handlerFns[store.name] = storeInstance[store.handler].bind(storeInstance);

if (!this.currentAction) {
throw new Error('waitFor called even though there is no action dispatching');
var message = 'waitFor called even though there is no action dispatching';
var meta = {
stores: stores
};
return this.dispatcher._throwOrCallErrorHandler(message, 'WAITFOR_NO_ACTION', this.context, meta);
}

@@ -159,0 +178,0 @@ this.currentAction.waitFor(stores, callback);

2

package.json
{
"name": "dispatchr",
"version": "1.0.3",
"version": "1.1.0",
"description": "A Flux dispatcher for applications that run on the server and the client.",

@@ -5,0 +5,0 @@ "main": "index.js",

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