Permalink
Browse files

do not publish in eventstore but publish in domain

  • Loading branch information...
1 parent d2636c2 commit 349aca85c2c703c32a7f0d5f5f591a72b768abfe @adrai committed Dec 7, 2013
View
@@ -23,11 +23,10 @@ It can be very useful as domain component if you work with (d)ddd, cqrs, eventde
aggregatesPath: __dirname + '/aggregates',
sagaHandlersPath: __dirname + '/sagaHandlers',
sagasPath: __dirname + '/sagas',
- publishingInterval: 20,
- forkEventDispatching: true,
snapshotThreshold: 10,
forcedQueuing: false,
- disableQueuing: false
+ disableQueuing: false,
+ handleUpdispatchedEvents: true
}, function(err) {
});
@@ -78,6 +77,12 @@ See [tests](https://github.com/adrai/node-cqrs-domain/tree/master/test) for deta
# Release Notes
+## v0.6.0
+
+- don't publish in eventstore but publish in domain
+- removed flags: publishingInterval, forkEventDispatching
+- added handleUpdispatchedEvents flag
+
## v0.5.3
- fix for async business rules (issue [#13](https://github.com/adrai/node-cqrs-domain/issues/13))
View
@@ -1,125 +1,136 @@
-var utils = require('../utils')
- , async = require('async')
- , _ = require('lodash');
+var utils = require('../utils'),
+ async = require('async'),
+ _ = require('lodash');
var Aggregate = function(id) {
- this.id = id;
- this.uncommittedEvents = [];
- this.attributes = { id: id, revision: 0, destroyed: false };
+ this.id = id;
+ this.uncommittedEvents = [];
+ this.attributes = { id: id, revision: 0, destroyed: false };
};
Aggregate.prototype = {
- set: function(data) {
- if (arguments.length === 2) {
- this.attributes[arguments[0]] = arguments[1];
- } else {
- for(var m in data) {
- this.attributes[m] = data[m];
- }
- }
- },
+ set: function(data) {
+ if (arguments.length === 2) {
+ this.attributes[arguments[0]] = arguments[1];
+ } else {
+ for(var m in data) {
+ this.attributes[m] = data[m];
+ }
+ }
+ },
- get: function(attr) {
- return this.attributes[attr];
- },
+ get: function(attr) {
+ return this.attributes[attr];
+ },
- toJSON: function() {
- // var parse = JSON.deserialize || JSON.parse;
- // var json = parse(JSON.stringify(this.attributes));
- // return json;
- return _.clone(this.attributes);
- },
+ toJSON: function() {
+ // var parse = JSON.deserialize || JSON.parse;
+ // var json = parse(JSON.stringify(this.attributes));
+ // return json;
+ return _.clone(this.attributes);
+ },
- toEvent: function(name, data) {
- var event = {
- event: name,
- payload: data || {}
- };
+ toEvent: function(name, data) {
+ var event = {
+ event: name,
+ payload: data || {}
+ };
- if (!event.payload.id) event.payload.id = this.id;
+ if (!event.payload.id) event.payload.id = this.id;
- return event;
- },
+ return event;
+ },
- loadFromHistory: function(data, events) {
- if (data) {
- this.set(data);
- }
+ loadFromHistory: function(data, events) {
+ if (data) {
+ this.set(data);
+ }
- if (events) {
- this.apply(_.map(events, function(evt) {
- evt.fromHistory = true;
- return evt;
- }));
- }
- },
+ if (events) {
+ this.apply(_.map(events, function(evt) {
+ evt.fromHistory = true;
+ return evt;
+ }));
+ }
+ },
- apply: function(events, callback) {
- var self = this;
+ apply: function(events, callback) {
+ var self = this;
- if (!_.isArray(events)) {
- events = [events];
- }
+ if (!_.isArray(events)) {
+ events = [events];
+ }
- var historyEvents = [];
- var newEvents = [];
- _.each(events, function(evt) {
- if (evt.fromHistory) {
- historyEvents.push(evt);
- } else {
- newEvents.push(evt);
- }
- });
-
- _.each(historyEvents, function(evt) {
- self[evt.event](evt.payload);
-
- if (self.attributes.revision < evt.head.revision) {
- self.attributes.revision = evt.head.revision;
- }
- });
-
- this.previousAttributes = this.toJSON();
-
- _.each(newEvents, function(evt) {
- self[evt.event](evt.payload);
- evt.head = { revision: ++self.attributes.revision };
- self.uncommittedEvents.push(evt);
- });
-
- if (callback) callback(null);
-
- return;
- },
-
- checkBusinessRules: function(callback) {
- var self = this;
- var changedAttributes = this.toJSON();
- var keys = [];
-
- if(!this.businessRules) return callback(null);
-
- async.each(this.businessRules, function(rule, callback) {
- rule.call(self, changedAttributes, self.previousAttributes, self.uncommittedEvents, function(ruleId, message) {
- if (ruleId) {
- if (!message) {
- message = ruleId;
- ruleId = arguments.callee.caller.name;
- }
- keys.push({ type: 'businessRule', ruleId: ruleId, message: message });
- }
- callback(null);
- });
- }, function() {
- if (keys.length > 0) {
- self.attributes = self.previousAttributes;
- callback(keys);
- } else {
- callback(null);
- }
- });
+ var historyEvents = [];
+ var newEvents = [];
+ _.each(events, function(evt) {
+ if (evt.fromHistory) {
+ historyEvents.push(evt);
+ } else {
+ newEvents.push(evt);
+ }
+ });
+
+ _.each(historyEvents, function(evt) {
+ self[evt.event](evt.payload);
+
+ if (self.attributes.revision < evt.head.revision) {
+ self.attributes.revision = evt.head.revision;
+ }
+ });
+
+ this.previousAttributes = this.toJSON();
+
+ _.each(newEvents, function(evt) {
+ self[evt.event](evt.payload);
+ evt.head = { revision: ++self.attributes.revision };
+ self.uncommittedEvents.push(evt);
+ });
+
+ if (callback) callback(null);
+
+ return;
+ },
+
+ checkBusinessRules: function(callback) {
+ var self = this;
+ var changedAttributes = this.toJSON();
+ var keys = [];
+
+ if(!this.businessRules) return callback(null);
+
+ async.each(this.businessRules, function(rule, callback) {
+ rule.call(self, changedAttributes, self.previousAttributes, self.uncommittedEvents, function(ruleId, message) {
+ if (ruleId) {
+ if (!message) {
+ message = ruleId;
+ ruleId = arguments.callee.caller.name;
+ }
+ keys.push({ type: 'businessRule', ruleId: ruleId, message: message });
+ }
+ callback(null);
+ });
+ }, function() {
+ if (keys.length > 0) {
+ self.attributes = self.previousAttributes;
+ callback(keys);
+ } else {
+ callback(null);
+ }
+ });
+ },
+
+ getSnapshotThreshold: function() {
+ if (this.snapshotThreshold) {
+ if (_.isFunction(this.snapshotThreshold)) {
+ return this.snapshotThreshold();
+ } else {
+ return this.snapshotThreshold;
+ }
}
+ return null;
+ }
};
Oops, something went wrong.

0 comments on commit 349aca8

Please sign in to comment.