Evented.js 988 B

1234567891011121314151617181920212223242526272829303132
  1. define("dojo/Evented", ["./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. "use strict";
  15. var after = aspect.after;
  16. function Evented(){
  17. }
  18. Evented.prototype = {
  19. on: function(type, listener){
  20. return on.parse(this, type, listener, function(target, type){
  21. return after(target, 'on' + type, listener, true);
  22. });
  23. },
  24. emit: function(type, event){
  25. var args = [this];
  26. args.push.apply(args, arguments);
  27. return on.emit.apply(on, args);
  28. }
  29. };
  30. return Evented;
  31. });