Module: UWA/Class/Events

UWA/Class/Events

Classes implementing or extending this Class will have extra methods to handle events.

Example

define('MyProject/Class/TaskList', [
    'UWA/Class',
    'UWA/Class/Debug',
    'UWA/Class/Events',
], function (Class, Debug, Events) {

    var TaskList = Class.extend(Debug, Events, {

        init: function () {

             // Add elements storage
             this.elements = {};
        },

        addElement: function(name, value) {

            // Display debug info using log method.
            this.log(UWA.String.format('addElement name={0}, value={1}', name, value));

            this.elements[name] = value;

            // Dispatch onAddElement event
            this.dispatchEvent('onAddElement', [name, value]);
        },

        onAddElement: function (name, value) {
            // Default MyClass "onAddElement" event listener.
        }
    });

    return TaskList;
});

require(['MyProject/Class/TaskList'], function (TaskList) {

var myTaskList = new TaskList();

// Enable debug mode, that will enable log output into the console.
myTaskList.setDebugMode(true);

// Add custom "onAddElement" event listener.
myTaskList.addEvent('onAddElement', function () {
   // Update your view or related object here.
});

// Call addElement
myTaskList.addElement('buy beer', 'duff');

});

Classes

UWA.Class.Events