diff --git a/lib/repository/couchRepository.js b/lib/repository/couchRepository.js index abb2f59..6860c69 100644 --- a/lib/repository/couchRepository.js +++ b/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); } diff --git a/lib/storage/couchStorage.js b/lib/storage/couchStorage.js index adae30a..abc14ad 100644 --- a/lib/storage/couchStorage.js +++ b/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. diff --git a/lib/view.js b/lib/view.js index 05e0d10..679f024 100644 --- a/lib/view.js +++ b/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 diff --git a/spec/storage/couchStorageSpec.js b/spec/storage/couchStorageSpec.js index fc16c41..8702d82 100644 --- a/spec/storage/couchStorageSpec.js +++ b/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()) }) }) diff --git a/spec/viewSpec.js b/spec/viewSpec.js index b5ed964..ba93467 100644 --- a/spec/viewSpec.js +++ b/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() {