eventinfo.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module utils/eventinfo
  7. */
  8. import spy from './spy';
  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. * The value which will be returned by {@link module:utils/emittermixin~EmitterMixin#fire}.
  55. *
  56. * It's `undefined` by default and can be changed by an event listener:
  57. *
  58. * dataController.fire( 'getSelectedContent', ( evt ) => {
  59. * // This listener will make `dataController.fire( 'getSelectedContent' )`
  60. * // always return an empty DocumentFragment.
  61. * evt.return = new DocumentFragment();
  62. *
  63. * // Make sure no other listeners are executed.
  64. * evt.stop();
  65. * } );
  66. *
  67. * @member #return
  68. */
  69. }
  70. }