Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactor couch storage

  • Loading branch information...
commit 9a9bf8a71028d8548890fbce70888fb25028437c 1 parent 0a8f153
@petrjanda authored
View
2  lib/repository/couchRepository.js
@@ -16,7 +16,7 @@ exports.createRepository = function(options) {
return instance;
}
-CouchRepository = function(options) {
+var CouchRepository = function(options) {
CouchDb.call(this, options);
}
View
15 lib/storage/couchStorage.js
@@ -1,6 +1,16 @@
var utils = require('../utils'),
CouchDb = require('../util/couchdb');
+var instance = null;
+
+exports.createStorage = function(options) {
+ if(!instance) {
+ instance = new CouchStorage(options);
+ }
+
+ return instance;
+}
+
/*
* Storage is the system component, used to persist view layer snapshots. Main
* motivation, is to lower the load for event storage and speed up the view
@@ -8,12 +18,11 @@ var utils = require('../utils'),
* component and can be even implemented on different persistance system from
* event storage.
*/
-module.exports = CouchStorage = function() {
- CouchDb.call(this, 'cqrs');
+var CouchStorage = function(options) {
+ CouchDb.call(this, options);
}
utils.inherits(CouchStorage, CouchDb);
-utils.singleton(CouchStorage);
/*
* Method called to persist current view state, to the database snapshot.
View
2  lib/view.js
@@ -1,5 +1,5 @@
var repo = require('./repository').getInstance(),
- storage = require('./storage/couchStorage').getInstance();
+ storage = require('./storage/couchStorage').createStorage();
/*
* View is the ultimate way, how to look on your data, wider then the scope
View
6 spec/storage/couchStorageSpec.js
@@ -41,17 +41,17 @@ describe('CouchStorage', function() {
}
beforeEach(function() {
- couchStorage = new CouchStorage();
+ couchStorage = CouchStorage.createStorage();
})
describe('instance', function() {
it('should get instance of CouchStorage', function() {
- var couchStorage = CouchStorage.getInstance()
+ var couchStorage = CouchStorage.createStorage()
expect(typeof couchStorage.request).toEqual('function');
})
it('should return just one instance', function() {
- expect(CouchStorage.getInstance()).toEqual(CouchStorage.getInstance())
+ expect(CouchStorage.createStorage()).toEqual(CouchStorage.createStorage())
})
})
View
4 spec/viewSpec.js
@@ -1,7 +1,7 @@
var util = require('util'),
- couchdb = require('../lib/repository/couchRepository').createRepository({database: 'foo'}),
+ couchdb = require('../lib/repository/couchRepository').createRepository(),
repository = require('../lib/repository').getInstance(),
- storage = require('../lib/storage/couchStorage').getInstance(),
+ storage = require('../lib/storage/couchStorage').createStorage(),
View = require('../lib/view');
describe('View', function() {
Please sign in to comment.
Something went wrong with that request. Please try again.