I'm trying to restrict what events coming from common message bus should be emitted to server.
Allowed events are on outgoingEvents
array. Problem is that to properly send them th server I need event name.
var Events = new EventEmitter();
var outgoingEvents = [
'messageSubmit'
];
var outgoingMessages = Observable.fromArray(outgoingEvents)
.flatMap(function(eventName) {
return Observable.fromEvent(Events, eventName);
}).subscribe(function() {
// need event name here to properly encode message:
// var eventName = ... should be 'messageSubmit'
// var args = [].slice.call(arguments, 1);
// var encoded = JSON.stringify({ name: eventName, args: args });
// socket.send(encoded);
});
Events.emit('messageSubmit', { message: 'Submitted!' }, {flags: 'ABC'});
It is possible to reshape objects that get emmited to inservable in function that comes third parameter in
.fromEvent
So it will be arguments of
.subscribe
: