This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Conversion#register() method.
- Loading branch information
Showing
2 changed files
with
96 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module engine/conversion/conversionhelpers | ||
*/ | ||
|
||
/** | ||
* Base class for conversion helpers. | ||
*/ | ||
export default class ConversionHelpers { | ||
/** | ||
* Creates a conversion helpers instance. | ||
* | ||
* @param {Array.<module:engine/conversion/downcastdispatcher~DowncastDispatcher| | ||
* module:engine/conversion/upcastdispatcher~UpcastDispatcher>} dispatcher | ||
*/ | ||
constructor( dispatcher ) { | ||
this._dispatchers = Array.isArray( dispatcher ) ? dispatcher : [ dispatcher ]; | ||
} | ||
|
||
/** | ||
* Registers a conversion helper. | ||
* | ||
* **Note**: See full usage example in the `{@link module:engine/conversion/conversion~Conversion#for conversion.for()}` | ||
* method description. | ||
* | ||
* @param {Function} conversionHelper The function to be called on event. | ||
* @returns {module:engine/conversion/downcasthelpers~DowncastHelpers|module:engine/conversion/upcasthelpers~UpcastHelpers} | ||
*/ | ||
add( conversionHelper ) { | ||
this._addToDispatchers( conversionHelper ); | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Helper function for the `Conversion` `.add()` method. | ||
* | ||
* Calls `conversionHelper` on each dispatcher from the group specified earlier in the `.for()` call, effectively | ||
* adding converters to all specified dispatchers. | ||
* | ||
* @private | ||
* @param {Function} conversionHelper | ||
*/ | ||
_addToDispatchers( conversionHelper ) { | ||
for ( const dispatcher of this._dispatchers ) { | ||
conversionHelper( dispatcher ); | ||
} | ||
} | ||
} |