Skip to content

Commit

Permalink
#11
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Jul 11, 2013
1 parent a2f35e0 commit 4c075ca
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -76,6 +76,10 @@ See [tests](https://github.com/adrai/node-cqrs-domain/tree/master/test) for deta

# Release Notes

## v0.4.1

- added optional snapshotThreshold on aggregate

## v0.4.0

- asynchronous api for saga
Expand Down
4 changes: 3 additions & 1 deletion lib/bases/commandHandlerBase.js
Expand Up @@ -88,7 +88,9 @@ CommandHandler.prototype = {
if (!err) {
stream.commit(function(err) {
// Check if snapshotting is needed.
if (stream.events.length >= self.options.snapshotThreshold) {
if (aggregate.snapshotThreshold && ((_.isFunction(aggregate.snapshotThreshold) && stream.events.length >= aggregate.snapshotThreshold()) ||
(_.isNumber(aggregate.snapshotThreshold) && stream.events.length >= aggregate.snapshotThreshold)) ||
stream.events.length >= self.options.snapshotThreshold) {
self.eventStore.createSnapshot(stream.streamId, stream.currentRevision(), aggregate.toJSON());
}
});
Expand Down
2 changes: 1 addition & 1 deletion licence
@@ -1,4 +1,4 @@
Copyright (c) 2012 Adriano Raiano
Copyright (c) 2013 Adriano Raiano

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"author": "adrai",
"name": "cqrs-domain",
"version": "0.4.0",
"version": "0.4.1",
"private": false,
"main": "index.js",
"engines": {
Expand Down
4 changes: 4 additions & 0 deletions test/integration/aggregates/dummyAggregate.js
Expand Up @@ -2,6 +2,10 @@ var base = require('../../../index').aggregateBase;

module.exports = base.extend({

// snapshotThreshold: 20,
// or
// snapshotThreshold: function() { return 12 + 10; },

changeDummy: function(data, callback) {
this.apply(this.toEvent('dummyChanged', data));

Expand Down

0 comments on commit 4c075ca

Please sign in to comment.