4.1The FXB.Message object, and multiple types

The parameter which is passed to OnMessage() is an FXB.Message object. A single message can carry multiple update types simultaneously — for example, a price change and an order change in the same OnMessage() call — so you must test each type you care about with a separate if block, using Msg.is(type).

Do not use switch/case, else if, or any other construct that matches at most one branch. These will silently drop every update whose type happens to come after an earlier match.

Correct:

Framework.OnMessage = function(Msg) {

if (Msg.is(FXB.MessageTypes.PRICE)) {

// ... update a quote board

}

if (Msg.is([FXB.MessageTypes.ORDER_OPEN, FXB.MessageTypes.ORDER_CLOSE])) { // ... update a trade list

}

};

Incorrect - else if skips the order update whenever the message is also a price update:

Framework.OnMessage = function(Msg) {

if (Msg.is(FXB.MessageTypes.PRICE)) {

// ...

} else if (Msg.is([FXB.MessageTypes.ORDER_OPEN, FXB.MessageTypes.ORDER_CLOSE])) {

// ... NEVER REACHED when the message also contains a PRICE update

}

};

Incorrect - switch has the same defect:

Framework.OnMessage = function(Msg) {

switch (Msg.type) { // Msg does not have a single "primary" type case FXB.MessageTypes.PRICE:

// ... break;

case FXB.MessageTypes.ORDER_OPEN:

// ... NEVER REACHED when the message also contains a PRICE update break;

}

};

FXB.Message is implemented as a Dictionary, which is what enables a single message to hold multiple update types at once.