Sfoglia il codice sorgente

Remove is() method from unnecessary view classes.

Mateusz Samsel 6 anni fa
parent
commit
e039a60478

+ 0 - 12
packages/ckeditor5-engine/src/view/document.js

@@ -133,18 +133,6 @@ export default class Document {
 	}
 
 	/**
-	 * Checks whether given object is of `document` type.
-	 *
-	 * Read more at {@link module:engine/view/view~View#is `View#is()`}.
-	 *
-	 * @param {String} type
-	 * @returns {Boolean}
-	 */
-	is( type ) {
-		return type == 'document' || type == 'view:document';
-	}
-
-	/**
 	 * Performs post-fixer loops. Executes post-fixer callbacks as long as none of them has done any changes to the model.
 	 *
 	 * @protected

+ 2 - 3
packages/ckeditor5-engine/src/view/documentfragment.js

@@ -94,9 +94,8 @@ export default class DocumentFragment {
 	}
 
 	/**
-	 * Checks whether given view tree object is of given type.
-	 *
-	 * Read more in {@link module:engine/view/node~Node#is `Node#is()`} and {@link module:engine/view/view~View#is `View#is()`}.
+	 * Checks whether given view tree object is of given type following the convention set by
+	 * {@link module:engine/view/node~Node#is `Node#is()`}.
 	 *
 	 * @param {String} type
 	 * @returns {Boolean}

+ 0 - 2
packages/ckeditor5-engine/src/view/documentselection.js

@@ -289,8 +289,6 @@ export default class DocumentSelection {
 	 *		selection.is( 'model:selection' ); // false
 	 *		selection.is( 'element' ); // false
 	 *
-	 * Read more at {@link module:engine/view/view~View#is `View#is()`}.
-	 *
 	 * @param {String} type
 	 * @returns {Boolean}
 	 */

+ 0 - 12
packages/ckeditor5-engine/src/view/domconverter.js

@@ -106,18 +106,6 @@ export default class DomConverter {
 	}
 
 	/**
-	 * Checks whether given object is of `domConverter` type.
-	 *
-	 * Read more at {@link module:engine/view/view~View#is `View#is()`}.
-	 *
-	 * @param {String} type
-	 * @returns {Boolean}
-	 */
-	is( type ) {
-		return type == 'domConverter' || type == 'view:domConverter';
-	}
-
-	/**
 	 * Binds given DOM element that represents fake selection to {@link module:engine/view/documentselection~DocumentSelection
 	 * document selection}. Document selection copy is stored and can be retrieved by
 	 * {@link module:engine/view/domconverter~DomConverter#fakeSelectionToView} method.

+ 0 - 12
packages/ckeditor5-engine/src/view/downcastwriter.js

@@ -55,18 +55,6 @@ export default class DowncastWriter {
 	}
 
 	/**
-	 * Checks whether given object is of `downcastWriter` type.
-	 *
-	 * Read more at {@link module:engine/view/view~View#is `View#is()`}.
-	 *
-	 * @param {String} type
-	 * @returns {Boolean}
-	 */
-	is( type ) {
-		return type == 'downcastWriter' || type == 'view:downcastWriter';
-	}
-
-	/**
 	 * Sets {@link module:engine/view/documentselection~DocumentSelection selection's} ranges and direction to the
 	 * specified location based on the given {@link module:engine/view/selection~Selectable selectable}.
 	 *

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

@@ -155,7 +155,7 @@ export default class Element extends Node {
 	 *		obj.is( 'text' ); // false
 	 *		obj.is( 'element', 'img' ); // false
 	 *
-	 * Read more in {@link module:engine/view/node~Node#is `Node#is()`} and {@link module:engine/view/view~View#is `View#is()`}.
+	 * Read more in {@link module:engine/view/node~Node#is `Node#is()`}.
 	 *
 	 * @param {String} type
 	 * @param {String} [name] Element name.

+ 0 - 12
packages/ckeditor5-engine/src/view/matcher.js

@@ -174,18 +174,6 @@ export default class Matcher {
 
 		return ( typeof pattern != 'function' && name && !( name instanceof RegExp ) ) ? name : null;
 	}
-
-	/**
-	 * Checks whether given object is of `matcher` type.
-	 *
-	 * Read more at {@link module:engine/view/view~View#is `View#is()`}.
-	 *
-	 * @param {String} type
-	 * @returns {Boolean}
-	 */
-	is( type ) {
-		return type == 'matcher' || type == 'view:matcher';
-	}
 }
 
 // Returns match information if {@link module:engine/view/element~Element element} is matching provided pattern.

+ 5 - 1
packages/ckeditor5-engine/src/view/node.js

@@ -295,13 +295,17 @@ export default class Node {
 	 * This method is useful when processing view tree objects that are of unknown type. For example, a function
 	 * may return {@link module:engine/view/documentfragment~DocumentFragment} or {@link module:engine/view/node~Node}
 	 * that can be either text node or element. This method can be used to check what kind of object is returned.
+	 * All checked types might be prefixed with `view:` to narrow search exclusively to view's objects.
+	 * That should prevent of situation where `model:node` accidentally might be considered as `view:node`.
+	 * Types are defined as name of the class written in [camelCase](https://en.wikipedia.org/wiki/Camel_case) notation.
+	 * E.g. class `RootEditableElement` will get type `rootEditableElement`.
 	 *
 	 *		obj.is( 'node' ); // true for any node, false for document fragment and text fragment
 	 *		obj.is( 'view:node' ); // true for any node, false for document fragment and text fragment
 	 *		obj.is( 'documentFragment' ); // true for document fragment, false for any node
 	 *		obj.is( 'view:documentFragment' ); // true for document fragment, false for any node
 	 *		obj.is( 'element' ); // true for any element, false for text node or document fragment
-	 *		obj.is( 'ciew:element' ); // true for any element, false for text node or document fragment
+	 *		obj.is( 'view:element' ); // true for any element, false for text node or document fragment
 	 *		obj.is( 'element', 'p' ); // true only for element which name is 'p'
 	 *		obj.is( 'view:element', 'p' ); // true only for element which name is 'p'
 	 *		obj.is( 'p' ); // shortcut for obj.is( 'element', 'p' )

+ 2 - 3
packages/ckeditor5-engine/src/view/position.js

@@ -207,9 +207,8 @@ export default class Position {
 	}
 
 	/**
-	 * Checks whether given object is of `position` type.
-	 *
-	 * Read more at {@link module:engine/view/view~View#is `View#is()`}.
+	 * Checks whether given object is of `position` type following the convention set by
+	 * {@link module:engine/view/node~Node#is `Node#is()`}.
 	 *
 	 * @param {String} type
 	 * @returns {Boolean}

+ 2 - 3
packages/ckeditor5-engine/src/view/range.js

@@ -395,9 +395,8 @@ export default class Range {
 	}
 
 	/**
-	 * Checks whether given object is of `range` type.
-	 *
-	 * Read more at {@link module:engine/view/view~View#is `View#is()`}.
+	 * Checks whether given object is of `range` type following the convention set by
+	 * {@link module:engine/view/node~Node#is `Node#is()`}.
 	 *
 	 * @param {String} type
 	 * @returns {Boolean}

+ 0 - 12
packages/ckeditor5-engine/src/view/renderer.js

@@ -119,18 +119,6 @@ export default class Renderer {
 	}
 
 	/**
-	 * Checks whether given object is of `renderer` type.
-	 *
-	 * Read more at {@link module:engine/view/view~View#is `View#is()`}.
-	 *
-	 * @param {String} type
-	 * @returns {Boolean}
-	 */
-	is( type ) {
-		return type == 'renderer' || type == 'view:renderer';
-	}
-
-	/**
 	 * Marks a view node to be updated in the DOM by {@link #render `render()`}.
 	 *
 	 * Note that only view nodes whose parents have corresponding DOM elements need to be marked to be synchronized.

+ 0 - 2
packages/ckeditor5-engine/src/view/selection.js

@@ -608,8 +608,6 @@ export default class Selection {
 	 *		selection.is( 'node' ); // false
 	 *		selection.is( 'element' ); // false
 	 *
-	 * Read more at {@link module:engine/view/view~View#is `View#is()`}.
-	 *
 	 * @param {String} type
 	 * @returns {Boolean}
 	 */

+ 2 - 3
packages/ckeditor5-engine/src/view/textproxy.js

@@ -141,9 +141,8 @@ export default class TextProxy {
 	}
 
 	/**
-	 * Checks whether given view tree object is of given type.
-	 *
-	 * Read more in {@link module:engine/view/node~Node#is `Node#is()`} and Read {@link module:engine/view/view~View#is `View#is()`}.
+	 * Checks whether given view tree object is of given type following the convention set by
+	 * {@link module:engine/view/node~Node#is `Node#is()`}.
 	 *
 	 * @param {String} type
 	 * @returns {Boolean}

+ 0 - 12
packages/ckeditor5-engine/src/view/treewalker.js

@@ -145,18 +145,6 @@ export default class TreeWalker {
 	}
 
 	/**
-	 * Checks whether given object is of `treeWalker` type.
-	 *
-	 * Read more at {@link module:engine/view/view~View#is `View#is()`}.
-	 *
-	 * @param {String} type
-	 * @returns {Boolean}
-	 */
-	is( type ) {
-		return type == 'treeWalker' || type == 'view:treeWalker';
-	}
-
-	/**
 	 * Moves {@link #position} in the {@link #direction} skipping values as long as the callback function returns `true`.
 	 *
 	 * For example:

+ 0 - 12
packages/ckeditor5-engine/src/view/upcastwriter.js

@@ -36,18 +36,6 @@ import Selection from './selection';
  */
 export default class UpcastWriter {
 	/**
-	 * Checks whether given object is of `upcastWriter` type.
-	 *
-	 * Read more at {@link module:engine/view/view~View#is `View#is()`}.
-	 *
-	 * @param {String} type
-	 * @returns {Boolean}
-	 */
-	is( type ) {
-		return type == 'upcastWriter' || type == 'view:upcastWriter';
-	}
-
-	/**
 	 * Creates a new {@link module:engine/view/documentfragment~DocumentFragment} instance.
 	 *
 	 * @param {module:engine/view/node~Node|Iterable.<module:engine/view/node~Node>} [children]

+ 0 - 34
packages/ckeditor5-engine/src/view/view.js

@@ -653,40 +653,6 @@ export default class View {
 	}
 
 	/**
-	 * Checks whether given object is of `view` type.
-	 *
-	 * All classes related to {@link module:engine/view/view~View} might contain `is` method,
-	 * which checks if given object belong to specific type. Types are defined as name of the class
-	 * written in [camelCase](https://en.wikipedia.org/wiki/Camel_case) notation. E.g. class `DocumentFragment`
-	 * will get type `documentFragment`. There might appear some additional possibilities to test types which will be described in
-	 * related documentation.
-	 *
-	 * It might simplify your code for cases, when you want to test unknown object for specific type.
-	 * Instead of using `instanceof` and importing entire class for testing, there might be used `is` method which test for given name.
-	 * There is also available `view:` prefix in each case, which gives more specific results.
-	 * It helps to distinguish view's classes from model's. Few examples how to use this method you can find below:
-	 *
-	 * 	const view = new View()
-	 * 	view.is( 'view' ) // return true
-	 *
-	 * 	const range = new Range( startPosition )
-	 * 	range.is( 'range' ) // return true
-	 * 	range.is( 'view:range' ) // return true
-	 * 	range.is( 'model:range' ) // return false
-	 *
-	 * 	const document = new Document();
-	 * 	document.is( 'model:document' ) // return true
-	 *
-	 * See also {@link module:engine/view/node~Node#is `Node#is()`} for some more details related to elements.
-	 *
-	 * @param {String} type
-	 * @returns {Boolean}
-	 */
-	is( type ) {
-		return type == 'view';
-	}
-
-	/**
 	 * Disables or enables rendering. If the flag is set to `true` then the rendering will be disabled.
 	 * If the flag is set to `false` and if there was some change in the meantime, then the rendering action will be performed.
 	 *