src/courier/PostMessageCourier.js
function _prepare(args, name, ontimeout) {
                var method;
                var ttl;
                var id = PostMessageUtilities.createUniqueSequence(MESSAGE_PREFIX + name + PostMessageUtilities.SEQUENCE_FORMAT);

                args.unshift(id, name);

                if (_isTwoWay(name)) {
                    if (1 < args.length && "function" === typeof args[args.length - 1]) {
                        method = args.pop();
                    }
                    else if (2 < args.length && !isNaN(args[args.length - 1]) && "function" === typeof args[args.length - 2]) {
                        ttl = parseInt(args.pop(), 10);
                        method = args.pop();
                    }

                    if (method) {
                        if (!this.callbackCache.set(id, method, ttl, function (id, callback) {
                                ontimeout();
                                _handleTimeout.call(this, id, callback);
                            }.bind(this))) {
                            // Cache is full, as a fail fast mechanism, we will not continue
                            return void 0;
                        }
                    }
                }

                return this.mapper.toMessage.apply(this.mapper, args);
            }
function _prepare(args, name, ontimeout) {
                var method;
                var ttl;
                var id = PostMessageUtilities.createUniqueSequence(MESSAGE_PREFIX + name + PostMessageUtilities.SEQUENCE_FORMAT);

                args.unshift(id, name);

                if (_isTwoWay(name)) {
                    if (1 < args.length && "function" === typeof args[args.length - 1]) {
                        method = args.pop();
                    }
                    else if (2 < args.length && !isNaN(args[args.length - 1]) && "function" === typeof args[args.length - 2]) {
                        ttl = parseInt(args.pop(), 10);
                        method = args.pop();
                    }

                    if (method) {
                        if (!this.callbackCache.set(id, method, ttl, function (id, callback) {
                                ontimeout();
                                _handleTimeout.call(this, id, callback);
                            }.bind(this))) {
                            // Cache is full, as a fail fast mechanism, we will not continue
                            return void 0;
                        }
                    }
                }

                return this.mapper.toMessage.apply(this.mapper, args);
            }
function _prepare ( args , name , ontimeout ) { var method ; var ttl ; var id = PostMessageUtilities . createUniqueSequence ( MESSAGE_PREFIX + name + PostMessageUtilities . SEQUENCE_FORMAT ) ; args . unshift ( id , name ) ; if ( _isTwoWay ( name ) ) { if ( 1 < args . length && "function" === typeof args [ args . length - 1 ] ) { method = args . pop ( ) ; } else if ( 2 < args . length && ! isNaN ( args [ args . length - 1 ] ) && "function" === typeof args [ args . length - 2 ] ) { ttl = parseInt ( args . pop ( ) , 10 ) ; method = args . pop ( ) ; } if ( method ) { if ( ! this . callbackCache . set ( id , method , ttl , function ( id , callback ) { ontimeout ( ) ; _handleTimeout . call ( this , id , callback ) ; } . bind ( this ) ) ) { // Cache is full, as a fail fast mechanism, we will not continue return void 0 ; } } } return this . mapper . toMessage . apply ( this . mapper , args ) ; }
Method for preparing the message to be posted via the postmessage and caching the callback to be called if needed
@param {Array} args - the arguments to pass to the message mapper
@param {String} name - the action type name (trigger, command, request)
@param {Function} [ontimeout] - the ontimeout measurement handler
@returns {Function} handler function for messages
@private
Method for preparing the message to be posted via the postmessage and caching the callback to be called if needed