services/sync/tps/extensions/mozmill/resource/driver/msgbroker.js

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, you can obtain one at http://mozilla.org/MPL/2.0/. */
     5 var EXPORTED_SYMBOLS = ['addListener', 'addObject',
     6                         'removeListener',
     7                         'sendMessage', 'log', 'pass', 'fail'];
     9 var listeners = {};
    11 // add a listener for a specific message type
    12 function addListener(msgType, listener) {
    13   if (listeners[msgType] === undefined) {
    14     listeners[msgType] = [];
    15   }
    17   listeners[msgType].push(listener);
    18 }
    20 // add each method in an object as a message listener
    21 function addObject(object) {
    22   for (var msgType in object) {
    23     addListener(msgType, object[msgType]);
    24   }
    25 }
    27 // remove a listener for all message types
    28 function removeListener(listener) {
    29   for (var msgType in listeners) {
    30     for (let i = 0; i < listeners.length; ++i) {
    31       if (listeners[msgType][i] == listener) {
    32         listeners[msgType].splice(i, 1); // remove listener from array
    33       }
    34     }
    35   }
    36 }
    38 function sendMessage(msgType, obj) {
    39   if (listeners[msgType] === undefined) {
    40     return;
    41   }
    43   for (let i = 0; i < listeners[msgType].length; ++i) {
    44     listeners[msgType][i](obj);
    45   }
    46 }
    48 function log(obj) {
    49   sendMessage('log', obj);
    50 }
    52 function pass(obj) {
    53   sendMessage('pass', obj);
    54 }
    56 function fail(obj) {
    57   sendMessage('fail', obj);
    58 }

mercurial