@serialized/serialized-client
Advanced tools
Comparing version 0.9.3 to 0.9.4
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var isFunction = function (value) { return value && (Object.prototype.toString.call(value) === "[object Function]" || "function" === typeof value || value instanceof Function); }; | ||
var AggregateRoot = /** @class */ (function () { | ||
@@ -20,3 +21,19 @@ function AggregateRoot(aggregateId, aggregateType) { | ||
this.currentVersion = response.aggregateVersion; | ||
response.events.map(function (e) { return _this['handle' + e.eventType](e); }); | ||
response.events.map(function (e) { | ||
var handlerName = 'handle' + e.eventType; | ||
var handler = _this[handlerName]; | ||
if (!(!handler && !isFunction(handler))) { | ||
_this[handlerName](e); | ||
} | ||
else { | ||
console.log("No handler for " + handlerName + ", will defer to generic handle() method"); | ||
var genericHandler = _this['handle']; | ||
if (!(!genericHandler && !isFunction(genericHandler))) { | ||
_this['handle'](e); | ||
} | ||
else { | ||
throw Error("No handler available for event type: " + e.eventType); | ||
} | ||
} | ||
}); | ||
}; | ||
@@ -23,0 +40,0 @@ AggregateRoot.prototype.getUncommittedEvents = function () { |
@@ -6,3 +6,3 @@ { | ||
"author": "Mattias Holmqvist", | ||
"version": "0.9.3", | ||
"version": "0.9.4", | ||
"main": "dist/index.js", | ||
@@ -9,0 +9,0 @@ "types": "dist/index.d.ts", |
48179
1020