namespace NT { /** Represents message priorities. */ export enum MessagePriority { /** Normal message priority, meaning the message is sent as soon as the queue allows. */ NORMAL , /** High message priority, meaning the message is sent immediately. */ HIGH } /** Represents a message which can be sent and processed across the system. */ export class Message { /** The code for this message, which is subscribed to and listened for. */ public code : string ; /** Free-form context data to be included with this message. */ public context : any ; /** The class instance which sent this message. */ public sender : any ; /** The priority of this message. */ public priority : MessagePriority ; param code param sender param context param priority public constructor ( code , sender , context ? , priority = MessagePriority . NORMAL ) { this . code = code ; this . sender = sender ; this . context = context ; this . priority = priority ; } param code param sender param context public static send ( code , sender , context ? ) { MessageBus . post ( new Message ( code , sender , context , MessagePriority . NORMAL ) ) ; } param code param sender param context public static sendPriority ( code , sender , context ? ) { MessageBus . post ( new Message ( code , sender , context , MessagePriority . HIGH ) ) ; } param code param handler public static subscribe ( code , handler ) { MessageBus . addSubscription ( code , handler , undefined ) ; } param code param callback public static subscribeCallback ( code , callback ) { MessageBus . addSubscription ( code , undefined , callback ) ; } param code param handler public static unsubscribe ( code , handler ) { MessageBus . removeSubscription ( code , handler , undefined ) ; } param code param callback public static unsubscribeCallback ( code , callback ) { MessageBus . removeSubscription ( code , undefined , callback ) ; } } }