Comments (7)
Do you mean to, for example, be able to log all events?
from sourced.
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.
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.
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.
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.
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.
I will look into it, thanks!
from sourced.
Related Issues (19)
- What to do about circular references within entities? HOT 1
- replace _.cloneDeep for snapshots with more performant default HOT 3
- How events work with a Service Bus. HOT 4
- Unhandled "Channel ended" rejection in tests HOT 3
- Question - Inter-process events HOT 4
- Dependency Dashboard
- replay / emit HOT 7
- How to handle Entity meta? HOT 9
- Best way to handle validation? HOT 2
- Typedef for Typescript HOT 1
- Race condition in constructor when extending an Entity HOT 15
- How to make `id` more clear. HOT 4
- Merge of snapshot with Entity null properties fails HOT 1
- Auth example not working on Node v 8.11.2 HOT 2
- replaying HOT 1
- The automated release is failing 🚨 HOT 7
- Entity constructor arity during deserialization HOT 5
- Missing License file. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sourced.