Permalink
Browse files

refactor couch storage

  • Loading branch information...
1 parent 0a8f153 commit 9a9bf8a71028d8548890fbce70888fb25028437c @petrjanda committed Apr 27, 2012
Showing with 19 additions and 10 deletions.
  1. +1 −1 lib/repository/couchRepository.js
  2. +12 −3 lib/storage/couchStorage.js
  3. +1 −1 lib/view.js
  4. +3 −3 spec/storage/couchStorageSpec.js
  5. +2 −2 spec/viewSpec.js
@@ -16,7 +16,7 @@ exports.createRepository = function(options) {
return instance;
}
-CouchRepository = function(options) {
+var CouchRepository = function(options) {
CouchDb.call(this, options);
}
@@ -1,19 +1,28 @@
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
* generate process, when client request comes. The storage is separate system
* 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
@@ -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
@@ -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
@@ -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() {

0 comments on commit 9a9bf8a

Please sign in to comment.