[256] | 1 | define(["./aspect", "./on"], function(aspect, on){ |
---|
| 2 | // summary: |
---|
| 3 | // The export of this module is a class that can be used as a mixin or base class, |
---|
| 4 | // to add on() and emit() methods to a class |
---|
| 5 | // for listening for events and emiting events: |
---|
| 6 | // |define(["dojo/Evented"], function(Evented){ |
---|
| 7 | // | var EventedWidget = dojo.declare([Evented, dijit._Widget], {...}); |
---|
| 8 | // | widget = new EventedWidget(); |
---|
| 9 | // | widget.on("open", function(event){ |
---|
| 10 | // | ... do something with event |
---|
| 11 | // | }); |
---|
| 12 | // | |
---|
| 13 | // | widget.emit("open", {name:"some event", ...}); |
---|
| 14 | |
---|
| 15 | "use strict"; |
---|
| 16 | var after = aspect.after; |
---|
| 17 | function Evented(){ |
---|
| 18 | } |
---|
| 19 | Evented.prototype = { |
---|
| 20 | on: function(type, listener){ |
---|
| 21 | return on.parse(this, type, listener, function(target, type){ |
---|
| 22 | return after(target, 'on' + type, listener, true); |
---|
| 23 | }); |
---|
| 24 | }, |
---|
| 25 | emit: function(type, event){ |
---|
| 26 | var args = [this]; |
---|
| 27 | args.push.apply(args, arguments); |
---|
| 28 | return on.emit.apply(on, args); |
---|
| 29 | } |
---|
| 30 | }; |
---|
| 31 | return Evented; |
---|
| 32 | }); |
---|