Code Monkey home page Code Monkey logo

Comments (7)

eddieajau avatar eddieajau commented on May 18, 2024

Do you mean to, for example, be able to log all events?

from sourced.

mateodelnorte avatar mateodelnorte commented on May 18, 2024

It's by design in that Entities publish events by inheriting the behavior of Node's standard EventEmitter class.

If I were to do this, I would just .enqueue('eventName', this.toJson()); both an event which describes exactly what action was just performed on an entity, as well as a more generic .enqueue('updated', this.toJson()); event. Then, you can listen for both the specific event or all. It would look something like:

Invoice.prototype.approved = function (param) {
  this.digest('approved', param);
  this.approved = true;
  this.approvedAt = param.approvedAt;
  this.approvedBy = param.approvedBy;
  this.enqueue('approved', this.toJson());
  this.enqueue('updated', this.toJson());
};

If that's not fancy enough for you (I tend to prefer code that is less fancy, and more obvious) you could combine the top two answers from here and monkey patch your entities to use EventEmitter2, which would allow you to use wildcards to determine which events fire your listeners. You could create a little factory function which instantiates your entity, monkey patches it, and gives it back to you - ready to roll.

from sourced.

oswdr avatar oswdr commented on May 18, 2024

Thanks for you reply.

What I meant is if it is possible to catch all events on for example on the repository. This makes it possible to have my read services listen to all events from all entities. Please, if this is bad design - let me know.

More specifically, current situation:

var repository = ...
var card = new Card();
card.initialize(cmd);
card.on('initialize', () => ...);
repository.commit(card);

Preferred situation:

// read side
repository.on('initialize', () => {
  // update read side
});


// write side
var repository = ...
var card = new Card();
card.initialize(cmd);
repository.commit(card);

from sourced.

mateodelnorte avatar mateodelnorte commented on May 18, 2024

The top scenario you have is preferred, as it's the actual entity being
initialized, not the repo. Note the difference between an Entity's .emit
and .enqueue. enqueue will do exactly as emit, but only after the entity
has been committed to the repo. That may be the missing part you're looking
for.

On Sep 20, 2016 2:44 PM, "Joey Osseman" [email protected] wrote:

Thanks for you reply.

What I meant is if it is possible to catch all events on for example on
the repository. This makes it possible to have my read services listen to
all events from all entities. Please, if this is bad design - let me know.

More specifically, current situation:

var repository = ...
var card = new Card();
card.initialize(cmd);
card.on('initialize', () => ...);
repository.commit(card, () => res.send());

Preferred situation:

var repository = ...
var card = new Card();
card.initialize(cmd);
repository.commit(card, () => res.send());
repository.on('initialize', () => ...);


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#19 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAh3X2wPS9zXVq4gO6qYNwsUWFs7Uhbuks5qsCmAgaJpZM4J68Ea
.

from sourced.

oswdr avatar oswdr commented on May 18, 2024

Thanks for the quick reply, one last question :-). How would my read side respond on these events? In other words, how would they know an event was thrown?

from sourced.

mateodelnorte avatar mateodelnorte commented on May 18, 2024

You'll publish a message to a read-side process, which will instruct it to
update your read data store. Look at servicebus for that.

On Sep 20, 2016 3:14 PM, "Joey Osseman" [email protected] wrote:

Thanks for the quick reply, one last question :-). How would my read side
respond on these events? In other words, how would they know an event was
thrown?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#19 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAh3Xz3DaXUA_iX7R-ZTp0H04QXtJkXXks5qsDCigaJpZM4J68Ea
.

from sourced.

oswdr avatar oswdr commented on May 18, 2024

I will look into it, thanks!

from sourced.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.