cqrs-eventdenormalizer
Advanced tools
Comparing version 1.14.12 to 1.15.0
@@ -95,2 +95,7 @@ var Definition = require('../definitionBase'), | ||
if (this.getNewIdForThisEventExtender) { | ||
debug('[' + this.name + '] found eventextender id getter in event'); | ||
return this.getNewIdForThisEventExtender(evt, callback); | ||
} | ||
debug('not found viewmodel id in event, generate new id'); | ||
@@ -224,6 +229,32 @@ this.collection.getNewId(callback); | ||
} | ||
} | ||
}, | ||
/** | ||
* Inject idGenerator for eventextender function if no id found. | ||
* @param {Function} fn The function to be injected. | ||
* @returns {EventExtender} to be able to chain... | ||
*/ | ||
useAsId: function (fn) { | ||
if (!fn || !_.isFunction(fn)) { | ||
var err = new Error('Please pass a valid function!'); | ||
debug(err); | ||
throw err; | ||
} | ||
if (fn.length === 2) { | ||
this.getNewIdForThisEventExtender = fn; | ||
return this; | ||
} | ||
this.getNewIdForThisEventExtender = function (evt, callback) { | ||
callback(null, fn(evt)); | ||
}; | ||
return this; | ||
}, | ||
}); | ||
module.exports = EventExtender; |
@@ -199,2 +199,7 @@ var Definition = require('../definitionBase'), | ||
if (this.getNewIdForThisViewBuilder) { | ||
debug('[' + this.name + '] found viewmodel id getter in event'); | ||
return this.getNewIdForThisViewBuilder(evt, callback); | ||
} | ||
debug('[' + this.name + '] not found viewmodel id in event, generate new id'); | ||
@@ -577,2 +582,28 @@ this.collection.getNewId(callback); | ||
/** | ||
* Inject idGenerator function if no id found. | ||
* @param {Function} fn The function to be injected. | ||
* @returns {ViewBuilder} to be able to chain... | ||
*/ | ||
useAsId: function (fn) { | ||
if (!fn || !_.isFunction(fn)) { | ||
var err = new Error('Please pass a valid function!'); | ||
debug(err); | ||
throw err; | ||
} | ||
if (fn.length === 2) { | ||
this.getNewIdForThisViewBuilder = fn; | ||
return this; | ||
} | ||
this.getNewIdForThisViewBuilder = function (evt, callback) { | ||
callback(null, fn(evt)); | ||
}; | ||
return this; | ||
}, | ||
/** | ||
* Inject useAsQuery function if no query and no id found. | ||
@@ -579,0 +610,0 @@ * @param {Function} fn The function to be injected. |
{ | ||
"author": "adrai", | ||
"name": "cqrs-eventdenormalizer", | ||
"version": "1.14.12", | ||
"version": "1.15.0", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -608,2 +608,10 @@ # Introduction | ||
}); | ||
// optional define a function to that returns an id that will be used as viewmodel id when id not specified in options or found | ||
//.useAsId(function (evt) { | ||
// return 'newId'; | ||
//}); | ||
// or | ||
//.useAsId(function (evt, callback) { | ||
// callback(null, 'newId'); | ||
//}); | ||
// optional define a function that returns a query that will be used as query to find the viewmodels (but do not define the query in the options) | ||
@@ -732,2 +740,11 @@ //.useAsQuery(function (evt) { | ||
}); | ||
// optional define a function to that returns an id that will be used as viewmodel id when id not specified in options or found | ||
//.useAsId(function (evt) { | ||
// return 'newId'; | ||
//}); | ||
// or | ||
//.useAsId(function (evt, callback) { | ||
// callback(null, 'newId'); | ||
//}); | ||
@@ -734,0 +751,0 @@ ### not for a collection |
@@ -0,1 +1,4 @@ | ||
## [v1.15.0](https://github.com/adrai/node-cqrs-eventdenormalizer/compare/v1.14.12...v1.15.0) | ||
- add useAsId methods to ViewModel and EventExtender [#75](https://github.com/adrai/node-cqrs-eventdenormalizer/pull/75) thanks to [nanov](https://github.com/nanov) | ||
## [v1.14.12](https://github.com/adrai/node-cqrs-eventdenormalizer/compare/v1.14.11...v1.14.12) | ||
@@ -2,0 +5,0 @@ - update viewmodel |
201972
4626
898