Skip to content

Commit

Permalink
Introducing 'gladys' event emitter variable, accessible everywhere. R…
Browse files Browse the repository at this point in the history
…eplace sails.config.Event ( still working but will be removed in the future )
  • Loading branch information
Pierre-Gilles committed Sep 29, 2015
1 parent b96e53f commit 7e1b1c6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion api/services/NotificationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ module.exports = {
Notification.create(NotificationObj,function NotificationCreated(err, notification){
if(err) return callback(err);

sails.config.Event.emit('newNotification', notification);
gladys.emit('notification', notification);

SocketService.sendDesktopMessageUser(userId, 'newNotification' , notification, function(err, nbOfMsgSent){
if(err) return callback(err);

Expand Down
5 changes: 5 additions & 0 deletions api/services/ScenarioService.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ module.exports = {
launcher: function(code, value, callback) {

// emit an event for modules

// deprecated way.. keeped for module
sails.config.Event.emit(code, value);

// new way
gladys.emit(code, value);

sails.log.info('ScenarioService : launcher : ' + code + ' : ' + value);
LauncherType.findOne({
code: code
Expand Down
2 changes: 1 addition & 1 deletion api/services/ScriptService.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function loadInSandbox (path, callback){

var sandbox = sails.config.scripts.defaultSandbox;

sails.config.Event.on('sailsReady', function(){
gladys.on('sailsReady', function(){
// adding sails.log function to sandbox
sandbox.sails = {};
sandbox.sails.log = sails.log;
Expand Down
4 changes: 4 additions & 0 deletions api/services/StartService.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ module.exports = {
if(err) return sails.log.warn(err);
});
SchedulerService.startEvery30MinutesScheduler();

// old way
sails.config.Event.emit('sailsReady');
// new way
gladys.emit('sailsReady');
}


Expand Down
2 changes: 1 addition & 1 deletion config/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@


var events = require('events');

global.gladys = new events.EventEmitter();
module.exports.Event = new events.EventEmitter();

0 comments on commit 7e1b1c6

Please sign in to comment.