thenativeweb / node-eventstore

EventStore Implementation in node.js
http://eventstore.js.org/
MIT License
539 stars 116 forks source link

How to pass 'options' into the custom implementation of 'Store'? #27

Closed nizachon closed 9 years ago

nizachon commented 9 years ago

Adriano,

Following your instructions (https://github.com/adrai/node-eventstore#own-db-implementation), I was able to have EventStore use my own implementation of Store.

But after being a happy camper for a few days, now I don't see a way to pass options into my Store's (and also, EventStore's) constructor.

https://github.com/adrai/node-eventstore/blob/master/index.js#L7 :

function getSpecificStore(options) {
  options = options || {};

  if (options.prototype instanceof Base) {
    return options;
  }

https://github.com/adrai/node-eventstore/blob/master/index.js#L48https://github.com/adrai/node-eventstore/blob/master/index.js#L48 :

module.exports = function(options) {
  options = options || {};

  var Store;

  try {
    Store = getSpecificStore(options);
  } catch (err) {
    throw err;
  }

  return new Eventstore(options, new Store(options));
};

module.exports.Store = Base;

It appears that when using the custom Store implementation the way you recommend, what gets passed as options into the factory method and EventStore constructor, is the constructor of the custom Store. Then the same Store constructor gets called with itself as the value of options...

Am I missing something here?

Thanks, -Leo

adrai commented 9 years ago

ok, I see the problem... What do you think on having the "own implementation" as second argument?

adrai commented 9 years ago

No, this is a bad idea, this will break the api of some other cqrs modules... but we could do something like:

var es = require('eventstore')({
  type: Store,
  host: 'localhost'
});
nizachon commented 9 years ago

I like it. Thank you!

nizachon commented 9 years ago

https://github.com/adrai/node-eventstore#own-db-implementation :

Shouldn't it be MyDB instead of Store:

var es = require('eventstore')({
  type: Store
});
// es.init...
adrai commented 9 years ago

Yes

Il giorno 27-gen-2015, alle ore 23:52, nizachon notifications@github.com<mailto:notifications@github.com> ha scritto:

https://github.com/adrai/node-eventstore#own-db-implementation :

Shouldn't it be MyDB instead of Store:

var es = require('eventstore')({ type: Store }); // es.init...

Reply to this email directly or view it on GitHubhttps://github.com/adrai/node-eventstore/issues/27#issuecomment-71746966.