API Documentation for: 0.11.10
Show:

File:src\components\RelaySelf.js

                        /**
                         * This component listens for specified local entity messages and re-broadcasts them on itself as other messages.
                         *
                         * @namespace platypus.components
                         * @class RelaySelf
                         * @uses platypus.Component
                         */
                        /*global platypus */
                        (function () {
                            'use strict';
                            
                            var trigger = function () {
                                var owner = this.owner;
                                
                                owner.trigger.apply(owner, arguments);
                            };
                        
                            return platypus.createComponentClass({
                                id: 'RelaySelf',
                                
                                properties: {
                                    /**
                                     * This is an object of key/value pairs. The keys are events this component is listening for locally, the value is the new event to be broadcast on this entity. The value can also be an array of events to be fired.
                                     *
                                     *      "events": {
                                     *          "sleeping": "good-night",
                                     *          "awake": ["alarm", "get-up"]
                                     *      }
                                     *
                                     * @property events
                                     * @type Object
                                     * @default null
                                     */
                                    events: null
                                },
                        
                                initialize: function () {
                                    var event = '',
                                        events = this.events;
                                    
                                    // Messages that this component listens for and then triggers on itself as a renamed message - useful as a logic place-holder for simple entities.
                                    if (events) {
                                        for (event in events) {
                                            if (events.hasOwnProperty(event)) {
                                                this.addEventListener(event, trigger.bind(this, events[event]));
                                            }
                                        }
                                    }
                                }
                            });
                        }());