eventinfo.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module utils/eventinfo
  7. */
  8. import spy from './spy.js';
  9. /**
  10. * The event object passed to event callbacks. It is used to provide information about the event as well as a tool to
  11. * manipulate it.
  12. */
  13. export default class EventInfo {
  14. /**
  15. * @param {Object} source The emitter.
  16. * @param {String} name The event name.
  17. */
  18. constructor( source, name ) {
  19. /**
  20. * The object that fired the event.
  21. *
  22. * @readonly
  23. * @member {Object}
  24. */
  25. this.source = source;
  26. /**
  27. * The event name.
  28. *
  29. * @readonly
  30. * @member {String}
  31. */
  32. this.name = name;
  33. /**
  34. * Path this event has followed. See {@link module:utils/emittermixin~EmitterMixin#delegate}.
  35. *
  36. * @readonly
  37. * @member {Array.<Object>}
  38. */
  39. this.path = [];
  40. // The following methods are defined in the constructor because they must be re-created per instance.
  41. /**
  42. * Stops the event emitter to call further callbacks for this event interaction.
  43. *
  44. * @method #stop
  45. */
  46. this.stop = spy();
  47. /**
  48. * Removes the current callback from future interactions of this event.
  49. *
  50. * @method #off
  51. */
  52. this.off = spy();
  53. }
  54. }