Meteor.js有辦法在服務器上發出全局事件嗎?例如Meteor.js - 服務器上的全局事件?
// how to set make myEmitter available across files/packages ?
myEmitter = new Npm.require('events').EventEmitter;
if(Meteor.isServer){
Meteor.methods({
'foo' : function(){
myEmitter.emit('fooEvent', { 'bar' : 'hello!'});
}
});
}
和
if(Meteor.isServer){
function doFoo(){
console.log('Foo done !');
}
myEmitter.on('fooEvent', doFoo);
}