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

Commit

Permalink
Remove is() method from unnecessary view classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Samsel committed Jun 26, 2019
1 parent 1ef1a56 commit e547b3f
Show file tree
Hide file tree
Showing 16 changed files with 14 additions and 136 deletions.
12 changes: 0 additions & 12 deletions src/view/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
5 changes: 2 additions & 3 deletions src/view/documentfragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 0 additions & 2 deletions src/view/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
12 changes: 0 additions & 12 deletions src/view/domconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions src/view/downcastwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
2 changes: 1 addition & 1 deletion src/view/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 0 additions & 12 deletions src/view/matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion src/view/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
Expand Down
5 changes: 2 additions & 3 deletions src/view/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
5 changes: 2 additions & 3 deletions src/view/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
12 changes: 0 additions & 12 deletions src/view/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()`}.
*
Expand Down
2 changes: 0 additions & 2 deletions src/view/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
5 changes: 2 additions & 3 deletions src/view/textproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
12 changes: 0 additions & 12 deletions src/view/treewalker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
*
Expand Down
12 changes: 0 additions & 12 deletions src/view/upcastwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
34 changes: 0 additions & 34 deletions src/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e547b3f

Please sign in to comment.