ソースを参照

Reorder the static methods and getters of StylesMap.

Maciej Gołaszewski 6 年 前
コミット
93253a8e3d

+ 1 - 1
packages/ckeditor5-engine/src/view/document.js

@@ -162,7 +162,7 @@ export default class Document {
 	}
 
 	addStyleProcessorRules( callback ) {
-		callback( StylesMap.processor );
+		callback( StylesMap._styleProcessor );
 	}
 
 	/**

+ 28 - 14
packages/ckeditor5-engine/src/view/stylesmap.js

@@ -18,7 +18,7 @@ export default class StylesMap {
 	/**
 	 * Creates Styles instance.
 	 */
-	constructor( styleProcessor ) {
+	constructor() {
 		/**
 		 * Keeps and internal representation of styles map. Normalized styles are kept as object tree to allow unified modification and
 		 * value access model using lodash's get, set, unset, etc methods.
@@ -35,7 +35,7 @@ export default class StylesMap {
 		// that two editors are connected through single style processor instance.
 		Object.defineProperty( this, '_styleProcessor', {
 			get() {
-				return styleProcessor || StylesMap.processor;
+				return StylesMap._styleProcessor;
 			},
 			enumerable: false
 		} );
@@ -63,18 +63,6 @@ export default class StylesMap {
 		return this.getStyleNames().length;
 	}
 
-	static get processor() {
-		if ( !this._processor ) {
-			this._processor = new StylesProcessor();
-		}
-
-		return this._processor;
-	}
-
-	static setProcessor( processor ) {
-		this._processor = processor;
-	}
-
 	/**
 	 * Set styles map to a new value.
 	 *
@@ -363,6 +351,32 @@ export default class StylesMap {
 
 		return parsed;
 	}
+
+	/**
+	 * Returns global StylesProcessor instance.
+	 *
+	 * @returns {module:engine/view/stylesmap~StylesProcessor}
+	 * @private
+	 */
+	static get _styleProcessor() {
+		if ( !this._processor ) {
+			this._processor = new StylesProcessor();
+		}
+
+		return this._processor;
+	}
+
+	/**
+	 * Set new StylesProcessor instance.
+	 *
+	 * This is an internal method used mostly in tests.
+	 *
+	 * @param processor
+	 * @protected
+	 */
+	static _setProcessor( processor ) {
+		this._processor = processor;
+	}
 }
 
 export class StylesProcessor {

+ 6 - 2
packages/ckeditor5-engine/tests/view/styles/backgroundstyles.js

@@ -9,10 +9,14 @@ import { addBackgroundStylesProcessor } from '../../../src/view/styles/backgroun
 describe( 'Background styles normalization', () => {
 	let styles;
 
-	beforeEach( () => {
+	before( () => {
 		const stylesProcessor = new StylesProcessor();
+		StylesMap._setProcessor( stylesProcessor );
 		addBackgroundStylesProcessor( stylesProcessor );
-		styles = new StylesMap( stylesProcessor );
+	} );
+
+	beforeEach( () => {
+		styles = new StylesMap();
 	} );
 
 	it( 'should normalize background', () => {

+ 7 - 3
packages/ckeditor5-engine/tests/view/styles/borderstyles.js

@@ -9,10 +9,14 @@ import { addBorderStylesProcessor } from '../../../src/view/styles/borderstyles'
 describe( 'Border styles normalization', () => {
 	let styles;
 
+	before( () => {
+		const stylesProcessor = new StylesProcessor();
+		StylesMap._setProcessor( stylesProcessor );
+		addBorderStylesProcessor( stylesProcessor );
+	} );
+
 	beforeEach( () => {
-		const converter = new StylesProcessor();
-		addBorderStylesProcessor( converter );
-		styles = new StylesMap( converter );
+		styles = new StylesMap();
 	} );
 
 	it( 'should parse border shorthand', () => {

+ 7 - 3
packages/ckeditor5-engine/tests/view/styles/marginstyles.js

@@ -9,10 +9,14 @@ import { addMarginStylesProcessor } from '../../../src/view/styles/marginstyles'
 describe( 'Margin styles normalizer', () => {
 	let styles;
 
+	before( () => {
+		const stylesProcessor = new StylesProcessor();
+		StylesMap._setProcessor( stylesProcessor );
+		addMarginStylesProcessor( stylesProcessor );
+	} );
+
 	beforeEach( () => {
-		const converter = new StylesProcessor();
-		addMarginStylesProcessor( converter );
-		styles = new StylesMap( converter );
+		styles = new StylesMap();
 	} );
 
 	it( 'should set all margins (1 value defined)', () => {

+ 7 - 3
packages/ckeditor5-engine/tests/view/styles/paddingstyles.js

@@ -9,10 +9,14 @@ import { addPaddingStylesProcessor } from '../../../src/view/styles/paddingstyle
 describe( 'Padding styles normalization', () => {
 	let styles;
 
+	before( () => {
+		const stylesProcessor = new StylesProcessor();
+		StylesMap._setProcessor( stylesProcessor );
+		addPaddingStylesProcessor( stylesProcessor );
+	} );
+
 	beforeEach( () => {
-		const converter = new StylesProcessor();
-		addPaddingStylesProcessor( converter );
-		styles = new StylesMap( converter );
+		styles = new StylesMap();
 	} );
 
 	it( 'should set all paddings (1 value defined)', () => {

+ 2 - 1
packages/ckeditor5-engine/tests/view/stylesmap.js

@@ -26,7 +26,8 @@ describe( 'StylesMap', () => {
 		stylesProcessor.setReducer( 'foo', getTopRightBottomLeftValueReducer( 'foo' ) );
 
 		addPaddingStylesProcessor( stylesProcessor );
-		stylesMap = new StylesMap( stylesProcessor );
+		StylesMap._setProcessor( stylesProcessor );
+		stylesMap = new StylesMap();
 	} );
 
 	describe( 'size getter', () => {