control-freak-ide/server/nodejs/dist/all/dojo/Evented.js
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

49 lines
1.4 KiB
JavaScript

/**
* @module dojo/Evented
**/
define([
"./aspect",
"./on"
], function (aspect, on) {
"use strict";
var after = aspect.after;
/**
* A class that can be used as a mixin or base class,
* to add on() and emit() methods to a class
* for listening for events and emitting events:
*
* @class module:dojo/Evented
* @example
*
* define(["dojo/Evented", "dojo/_base/declare", "dojo/Stateful"], function(Evented, declare, Stateful){
var EventedStateful = declare([Evented, Stateful], {...});
var instance = new EventedStateful();
instance.on("open", function(event){
// ... do something with event
});
instance.emit("open", {name:"some event", ...});
*/
function Evented() {
// summary:
// A class that can be used as a mixin or base class,
// to add on() and emit() methods to a class
// for listening for events and emitting events:
// example:
// |
}
Evented.prototype = {
on: function (type, listener) {
return on.parse(this, type, listener, function (target, type) {
return after(target, 'on' + type, listener, true);
});
},
emit: function (type, event) {
var args = [this];
args.push.apply(args, arguments);
return on.emit.apply(on, args);
}
};
return Evented;
});