Comparing version 1.5.0 to 1.6.0
@@ -45,2 +45,6 @@ 'use strict'; | ||
}); | ||
this.defineShouldHandle(function (evt, saga) { | ||
return true; | ||
}); | ||
} | ||
@@ -324,7 +328,17 @@ | ||
self.sagaFn.call(sagaThis, self.getPayload(evt), sagaModel, function (err) { | ||
self.shouldHandle(evt, sagaModel, function (err, doHandle) { | ||
if (err) { | ||
return callb(err); | ||
} | ||
callb(null, sagaModel); | ||
if (!doHandle) { | ||
return callb(null, null); | ||
} | ||
self.sagaFn.call(sagaThis, self.getPayload(evt), sagaModel, function (err) { | ||
if (err) { | ||
return callb(err); | ||
} | ||
callb(null, sagaModel); | ||
}); | ||
}); | ||
@@ -361,3 +375,3 @@ }, | ||
* @param {Function} fn The function to be injected. | ||
* @returns {ProcessManagement} to be able to chain... | ||
* @returns {Saga} to be able to chain... | ||
*/ | ||
@@ -381,2 +395,26 @@ useAsId: function (fn) { | ||
return this; | ||
}, | ||
/** | ||
* Inject shouldHandle function. | ||
* @param {Function} fn The function to be injected. | ||
* @returns {Saga} to be able to chain... | ||
*/ | ||
defineShouldHandle: function (fn) { | ||
if (!fn || !_.isFunction(fn)) { | ||
var err = new Error('Please pass a valid function!'); | ||
debug(err); | ||
throw err; | ||
} | ||
if (fn.length === 3) { | ||
this.shouldHandle = fn; | ||
return this; | ||
} | ||
this.shouldHandle = function (evt, saga, callback) { | ||
callback(null, fn(evt, saga)); | ||
}; | ||
return this; | ||
} | ||
@@ -383,0 +421,0 @@ |
{ | ||
"author": "adrai", | ||
"name": "cqrs-saga", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"private": false, | ||
@@ -14,3 +14,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"async": "1.0.0", | ||
"async": "1.2.1", | ||
"debug": "2.2.0", | ||
@@ -17,0 +17,0 @@ "dotty": "0.0.2", |
@@ -450,2 +450,11 @@ # Introduction | ||
//}); | ||
// | ||
// optional define a function that checks if an event should be handled | ||
//.defineShouldHandle(function (evt, saga) { | ||
// return true; | ||
//}); | ||
// or | ||
//.defineShouldHandle(function (evt, saga, callback) { | ||
// callback(null, true'); | ||
//}); | ||
@@ -452,0 +461,0 @@ |
@@ -0,1 +1,4 @@ | ||
## [v1.6.0](https://github.com/adrai/node-cqrs-saga/compare/v1.5.0...v1.6.0) | ||
- introduce possibility to define a shouldHandle function | ||
## [v1.5.0](https://github.com/adrai/node-cqrs-saga/compare/v1.4.0...v1.5.0) | ||
@@ -2,0 +5,0 @@ - when using revisionGuard, always save the last event |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4205
553
270112
+ Addedasync@1.2.1(transitive)
- Removedasync@1.0.0(transitive)
Updatedasync@1.2.1