From e547b3f646aaf1e19a4205ad7e1943d0dd51f590 Mon Sep 17 00:00:00 2001 From: Mateusz Samsel Date: Wed, 19 Jun 2019 13:09:03 +0200 Subject: [PATCH] Remove is() method from unnecessary view classes. --- src/view/document.js | 12 ------------ src/view/documentfragment.js | 5 ++--- src/view/documentselection.js | 2 -- src/view/domconverter.js | 12 ------------ src/view/downcastwriter.js | 12 ------------ src/view/element.js | 2 +- src/view/matcher.js | 12 ------------ src/view/node.js | 6 +++++- src/view/position.js | 5 ++--- src/view/range.js | 5 ++--- src/view/renderer.js | 12 ------------ src/view/selection.js | 2 -- src/view/textproxy.js | 5 ++--- src/view/treewalker.js | 12 ------------ src/view/upcastwriter.js | 12 ------------ src/view/view.js | 34 ---------------------------------- 16 files changed, 14 insertions(+), 136 deletions(-) diff --git a/src/view/document.js b/src/view/document.js index c8a76b812..376abdde3 100644 --- a/src/view/document.js +++ b/src/view/document.js @@ -132,18 +132,6 @@ export default class Document { this.stopListening(); } - /** - * 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. * diff --git a/src/view/documentfragment.js b/src/view/documentfragment.js index a66e21861..16e03d7fe 100644 --- a/src/view/documentfragment.js +++ b/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} diff --git a/src/view/documentselection.js b/src/view/documentselection.js index b8c0c419b..ab4225688 100644 --- a/src/view/documentselection.js +++ b/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} */ diff --git a/src/view/domconverter.js b/src/view/domconverter.js index dfa89a73b..66505be86 100644 --- a/src/view/domconverter.js +++ b/src/view/domconverter.js @@ -105,18 +105,6 @@ export default class DomConverter { this._fakeSelectionMapping = new WeakMap(); } - /** - * 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 diff --git a/src/view/downcastwriter.js b/src/view/downcastwriter.js index bd872a41c..e24bfd5ba 100644 --- a/src/view/downcastwriter.js +++ b/src/view/downcastwriter.js @@ -54,18 +54,6 @@ export default class DowncastWriter { this._cloneGroups = new Map(); } - /** - * 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}. diff --git a/src/view/element.js b/src/view/element.js index 707d67ee0..0efc962b3 100644 --- a/src/view/element.js +++ b/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. diff --git a/src/view/matcher.js b/src/view/matcher.js index d77d77992..e8e32e8b6 100644 --- a/src/view/matcher.js +++ b/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. diff --git a/src/view/node.js b/src/view/node.js index 04e9ddb87..f349d97cc 100644 --- a/src/view/node.js +++ b/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' ) diff --git a/src/view/position.js b/src/view/position.js index 0c4ae255e..c0e7ae748 100644 --- a/src/view/position.js +++ b/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} diff --git a/src/view/range.js b/src/view/range.js index 43478df21..174952fda 100644 --- a/src/view/range.js +++ b/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} diff --git a/src/view/renderer.js b/src/view/renderer.js index 74c626ae4..76099b3f5 100644 --- a/src/view/renderer.js +++ b/src/view/renderer.js @@ -118,18 +118,6 @@ export default class Renderer { this._fakeSelectionContainer = null; } - /** - * 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()`}. * diff --git a/src/view/selection.js b/src/view/selection.js index 2e76573de..dd17d4fa1 100644 --- a/src/view/selection.js +++ b/src/view/selection.js @@ -606,8 +606,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} */ diff --git a/src/view/textproxy.js b/src/view/textproxy.js index 159e294dc..ea3ee8f5e 100644 --- a/src/view/textproxy.js +++ b/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} diff --git a/src/view/treewalker.js b/src/view/treewalker.js index 5581dc64d..b6f04b3c7 100644 --- a/src/view/treewalker.js +++ b/src/view/treewalker.js @@ -140,18 +140,6 @@ export default class TreeWalker { return this; } - /** - * 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`. * diff --git a/src/view/upcastwriter.js b/src/view/upcastwriter.js index ec0a83736..990e6e096 100644 --- a/src/view/upcastwriter.js +++ b/src/view/upcastwriter.js @@ -35,18 +35,6 @@ import Selection from './selection'; * writer.appendChild( text, someViewElement ); */ 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. * diff --git a/src/view/view.js b/src/view/view.js index 296676a1c..7c6e6a1d5 100644 --- a/src/view/view.js +++ b/src/view/view.js @@ -645,40 +645,6 @@ export default class View { return new Selection( selectable, placeOrOffset, options ); } - /** - * 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.