# all files / TypeScript.NET/source/System/Collections/Array/ Dispatch.js

93.18% Statements 41/44
80% Branches 24/30
100% Functions 5/5
95.24% Lines 40/42

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67

    1×
    1×
    1×

    1×
    1×
    1×
    1×
    5×
    4×
    6×
    6×
    1×
    5×
    5×

    3×
    1×
    2×
    1×

    1×
    1×
    6×
    1×
    5×
    5×
    4×
    6×
    6×
    6×

    3×
    3×
    1×
    2×
    1×

    4×

    1×
    1×
    4×

    1×
    1×
    1×

     /*!
     * @author electricessence / https://github.com/electricessence/
     * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
     */
    (function (factory) {
        Eif (typeof module === 'object' && typeof module.exports === 'object') {
            var v = factory(require, exports); Iif (v !== undefined) module.exports = v;
        }
        else if (typeof define === 'function' && define.amd) {
            define(["require", "exports", "../../Types", "./Utility"], factory);
        }
    })(function (require, exports) {
        "use strict";
        var Types_1 = require("../../Types");
        var Utility_1 = require("./Utility");
        var VOID0 = void (0);
        function unsafe(listeners, payload, trap) {
            if (listeners && listeners.length) {
                for (var i = 0, len = listeners.length; i < len; i++) {
                    var fn = listeners[i];
                    if (!fn)
                        continue;
                    try {
                        fn(payload);
                    }
                    catch (ex) {
                        if (!trap)
                            throw ex;
                        else if (Types_1.Type.isFunction(trap))
                            trap(ex, i);
                    }
                }
            }
        }
        exports.unsafe = unsafe;
        function mapped(listeners, payload, trap) {
            if (!listeners)
                return null;
            var result = Utility_1.copy(listeners);
            if (listeners.length) {
                for (var i = 0, len = result.length; i < len; i++) {
                    var fn = result[i];
                    try {
                        result[i] = fn
                            ? fn(payload)
                            : VOID0;
                    }
                    catch (ex) {
                        result[i] = VOID0;
                        if (!trap)
                            throw ex;
                        else if (Types_1.Type.isFunction(trap))
                            trap(ex, i);
                    }
                }
            }
            return result;
        }
        exports.mapped = mapped;
        function dispatch(listeners, payload, trap) {
            unsafe(Utility_1.copy(listeners), payload, trap);
        }
        exports.dispatch = dispatch;
        Object.defineProperty(exports, "__esModule", { value: true });
        exports.default = dispatch;
    });
    //# sourceMappingURL=Dispatch.js.map