conversionhelpers.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 engine/conversion/conversionhelpers
  7. */
  8. /**
  9. * Base class for conversion helpers.
  10. */
  11. export default class ConversionHelpers {
  12. /**
  13. * Creates a conversion helpers instance.
  14. *
  15. * @param {Array.<module:engine/conversion/downcastdispatcher~DowncastDispatcher|
  16. * module:engine/conversion/upcastdispatcher~UpcastDispatcher>} dispatchers
  17. */
  18. constructor( dispatchers ) {
  19. this._dispatchers = dispatchers;
  20. }
  21. /**
  22. * Registers a conversion helper.
  23. *
  24. * **Note**: See full usage example in the `{@link module:engine/conversion/conversion~Conversion#for conversion.for()}`
  25. * method description.
  26. *
  27. * @param {Function} conversionHelper The function to be called on event.
  28. * @returns {module:engine/conversion/downcasthelpers~DowncastHelpers|module:engine/conversion/upcasthelpers~UpcastHelpers}
  29. */
  30. add( conversionHelper ) {
  31. for ( const dispatcher of this._dispatchers ) {
  32. conversionHelper( dispatcher );
  33. }
  34. return this;
  35. }
  36. }