-
Notifications
You must be signed in to change notification settings - Fork 1
/
Evented.js
36 lines (35 loc) · 1.05 KB
/
Evented.js
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
define(["./aspect", "./on"], function(aspect, on){
// module:
// dojo/Evented
"use strict";
var after = aspect.after;
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:
// | 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", ...});
}
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;
});