Sails: EventEmitter on Models

Created on 16 Nov 2016  路  7Comments  路  Source: balderdashy/sails

Sails version:0.12.4
Node version:6.4.0
NPM version:3.10.3
Operating system:OSX 10.12.1



Hello, first of all, I love sails. It's a great MVC framework for node, I would like to know it would be a good thing to add EventEmitter to Models, I think it would be an enhancement for watching Models inside the app, not restricted to sockets.

The only way to listen for events on a Model, you can use the current API for websockets
http://sailsjs.org/documentation/reference/web-sockets/resourceful-pub-sub

Is there any way I can listen for model events from anywhere else, a hook for example?

needs cleanup question

All 7 comments

Hi @agustinkassis! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

_If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]._

ok, fixed!

Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again.

_If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]._

@agustinkassis my experience has been that using EventEmitters in app-level code built on Node.js can sometimes lead to maintainability issues. But you _can_ use lifecycle callbacks to achieve this effect. Hope that helps!

I would use lifecycle callbacks to emit the event, precisely eventEmitter is better for maintainability as it provides loose coupling, there should be a way to listen for model events from hooks as not related code shouldn't be embedded inside a lifecycle method.

Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again.

If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected].

Thanks for posting, @agustinkassis. I'm a repo bot-- nice to meet you!

The issue queue in this repo is for verified bugs with documented features. Unfortunately, we can't leave some other types of issues marked as "open". This includes bug reports about undocumented features or unofficial plugins, as well as feature requests, questions, and commentary about the core framework. Please review our contribution guide for details.

If you're here looking for help and can't find it, visit StackOverflow, our Google Group or our chat room. But please do not let this disrupt future conversation in this issue! I am only marking it as "closed" to keep organized.

Thanks so much for your help!

If I am mistaken, and this issue is about a _critical bug with a documented feature_, please accept my sincerest apologies-- I am but a humble bot working to make GitHub a better place. If you open a new issue, a member of the core team will take a look ASAP.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sytten picture Sytten  路  4Comments

anissen picture anissen  路  3Comments

3imed-jaberi picture 3imed-jaberi  路  3Comments

alxndrsn picture alxndrsn  路  4Comments

Noitidart picture Noitidart  路  4Comments