Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Removed unnecessary HeadingCommand properties #79

Merged
merged 1 commit into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ export default class Heading extends Plugin {

/**
* Returns heading options as defined in `config.heading.options` but processed to consider
* editor localization, i.e. to display {@link module:heading/headingcommand~HeadingOption}
* editor localization, i.e. to display {@link module:heading/heading~HeadingOption}
* in the correct language.
*
* Note: The reason behind this method is that there's no way to use {@link module:utils/locale~Locale#t}
* when the user config is defined because the editor does not exist yet.
*
* @private
* @returns {Array.<module:heading/headingcommand~HeadingOption>}.
* @returns {Array.<module:heading/heading~HeadingOption>}.
*/
_getLocalizedOptions() {
const editor = this.editor;
Expand Down Expand Up @@ -159,3 +159,12 @@ export default class Heading extends Plugin {
function getCommandsBindingTargets( commands, attribute ) {
return Array.prototype.concat( ...commands.map( c => [ c, attribute ] ) );
}

/**
* Heading option descriptor.
*
* @typedef {Object} module:heading/heading~HeadingOption
* @property {String} modelElement Element's name in the model.
* @property {String} viewElement The name of the view element that will be used to represent the model element in the view.
* @property {String} title The user-readable title of the option.
*/
46 changes: 10 additions & 36 deletions src/headingcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ export default class HeadingCommand extends Command {
* Creates an instance of the command.
*
* @param {module:core/editor/editor~Editor} editor Editor instance.
* @param {module:heading/headingcommand~HeadingOption} option An option to be used by the command instance.
* @param {String} modelElement Name of the element which this command will apply in the model.
*/
constructor( editor, option ) {
constructor( editor, modelElement ) {
super( editor );

Object.assign( this, option );
/**
* Unique identifier of the command, also element's name in the model.
* See {@link module:heading/heading~HeadingOption}.
*
* @readonly
* @member {String}
*/
this.modelElement = modelElement;

/**
* Value of the command, indicating whether it is applied in the context
Expand All @@ -45,30 +52,6 @@ export default class HeadingCommand extends Command {
this.refreshValue();
this.refreshState();
} );

/**
* Unique identifier of the command, also element's name in the model.
* See {@link module:heading/headingcommand~HeadingOption}.
*
* @readonly
* @member {String} #modelElement
*/

/**
* Element this command creates in the view.
* See {@link module:heading/headingcommand~HeadingOption}.
*
* @readonly
* @member {String} #viewElement
*/

/**
* User-readable title of the command.
* See {@link module:heading/headingcommand~HeadingOption}.
*
* @readonly
* @member {String} #title
*/
}

/**
Expand Down Expand Up @@ -147,12 +130,3 @@ function checkCanBecomeHeading( block, heading, schema ) {
inside: Position.createBefore( block )
} );
}

/**
* Heading option descriptor.
*
* @typedef {Object} module:heading/headingcommand~HeadingOption
* @property {String} modelElement Element's name in the model.
* @property {String} viewElement The name of the view element that will be used to represent the model element in the view.
* @property {String} title The user-readable title of the option.
*/
2 changes: 1 addition & 1 deletion src/headingengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class HeadingEngine extends Plugin {
.toElement( option.modelElement );

// Register the heading command for this option.
editor.commands.set( option.modelElement, new HeadingCommand( editor, option ) );
editor.commands.set( option.modelElement, new HeadingCommand( editor, option.modelElement ) );
}
}
}
Expand Down
18 changes: 5 additions & 13 deletions tests/headingcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe( 'HeadingCommand', () => {
schema.registerItem( 'paragraph', '$block' );

for ( const option of options ) {
commands[ option.modelElement ] = new HeadingCommand( editor, option );
commands[ option.modelElement ] = new HeadingCommand( editor, option.modelElement );
schema.registerItem( option.modelElement, '$block' );
}

Expand All @@ -47,18 +47,10 @@ describe( 'HeadingCommand', () => {
}
} );

describe( 'basic properties', () => {
for ( const option of options ) {
test( option );
}

function test( { modelElement, viewElement, title } ) {
it( `are set for option.modelElement = ${ modelElement }`, () => {
expect( commands[ modelElement ].modelElement ).to.equal( modelElement );
expect( commands[ modelElement ].viewElement ).to.equal( viewElement );
expect( commands[ modelElement ].title ).to.equal( title );
} );
}
describe( 'modelElement', () => {
it( 'is set', () => {
expect( commands.heading1.modelElement ).to.equal( 'heading1' );
} );
} );

describe( 'value', () => {
Expand Down