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 model's classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Samsel committed Jun 17, 2019
1 parent 64b7bb0 commit f8f14eb
Show file tree
Hide file tree
Showing 18 changed files with 10 additions and 156 deletions.
12 changes: 0 additions & 12 deletions src/model/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,4 @@ export default class Batch {

return operation;
}

/**
* Checks whether given object is of `batch` type.
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @param {String} type
* @returns {Boolean}
*/
is( type ) {
return type == 'batch' || type == 'model:batch';
}
}
12 changes: 0 additions & 12 deletions src/model/differ.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,18 +519,6 @@ export default class Differ {
}
}

/**
* Checks whether given object is of `differ` type.
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @param {String} type
* @returns {Boolean}
*/
is( type ) {
return type == 'differ' || type == 'model:differ';
}

/**
* Resets `Differ`. Removes all buffered changes.
*/
Expand Down
12 changes: 0 additions & 12 deletions src/model/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,6 @@ export default class Document {
return Array.from( this.roots, root => root.rootName ).filter( name => name != graveyardName );
}

/**
* Checks whether given object is of `document` type.
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @param {String} type
* @returns {Boolean}
*/
is( type ) {
return type == 'document' || type == 'model:document';
}

/**
* Used to register a post-fixer callback. A post-fixer mechanism guarantees that the features
* will operate on a correct model state.
Expand Down
2 changes: 1 addition & 1 deletion src/model/documentfragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class DocumentFragment {
/**
* Checks whether given model tree object is of given type.
*
* Read more in {@link module:engine/model/node~Node#is `Node#is()`} and {@link module:engine/model/model~Model#is `Model#is()`}.
* Read more in {@link module:engine/model/node~Node#is `Node#is()`}.
*
* @param {String} type
* @returns {Boolean}
Expand Down
2 changes: 0 additions & 2 deletions src/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,6 @@ export default class DocumentSelection {
* selection.is( 'model:node' ); // false
* selection.is( 'element' ); // false
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @param {String} type
* @returns {Boolean}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/model/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class Element extends Node {
* obj.is( 'view:element' ); // false
* obj.is( 'element', 'image' ); // false
*
* Read more in {@link module:engine/model/node~Node#is `Node#is()`} and {@link module:engine/model/model~Model#is `Model#is()`}.
* Read more in {@link module:engine/model/node~Node#is `Node#is()`}.
*
* @param {String} type Type to check when `name` parameter is present.
* Otherwise, it acts like the `name` parameter.
Expand Down
12 changes: 0 additions & 12 deletions src/model/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,6 @@ export default class History {
this._undoneOperations.add( undoneOperation );
}

/**
* Checks whether given object is of `history` type.
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @param {String} type
* @returns {Boolean}
*/
is( type ) {
return type == 'history' || type == 'model:history';
}

/**
* Checks whether given `operation` is undoing any other operation.
*
Expand Down
14 changes: 1 addition & 13 deletions src/model/markercollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,6 @@ export default class MarkerCollection {
return this._markers.get( markerName ) || null;
}

/**
* Checks whether given object is of `markerCollection` type.
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @param {String} type
* @returns {Boolean}
*/
is( type ) {
return type == 'markerCollection' || type == 'model:markerCollection';
}

/**
* Creates and adds a {@link ~Marker marker} to the `MarkerCollection` with given name on given
* {@link module:engine/model/range~Range range}.
Expand Down Expand Up @@ -463,7 +451,7 @@ class Marker {
/**
* Checks whether given object is of `marker` type.
*
* Read more at {@link module:engine/model/model~Model#is}.
* Read more at {@link module:engine/model/model~Node#is}.
*
* @param {String} type
* @returns {Boolean}
Expand Down
36 changes: 0 additions & 36 deletions src/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,42 +716,6 @@ export default class Model {
this.stopListening();
}

/**
* Checks whether given object is of `model` type.
*
* All classes related to {@link module:engine/model/model~Model} 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 `LiveRange`
* will get type `liveRange`. There might appear some additional possibilities to test types which will be described in
* related documentation.
*
* Method 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 `model:` prefix in each case, which gives more specific results.
* It helps to distinguish model's classes from view's. Few examples how to use this method you can find below:
*
* const model = new Model();
* model.is( 'model' ) // return true
*
* const range = new LiveRange( startPosition )
* range.is( 'range' ) // return true
* range.is( 'liveRange' ) // return true
* range.is( 'model:range' ) // return true
* range.is( 'model:liveRange' ) // return true
* range.is( 'view:range' ) // return false
*
* const document = new Document();
* document.is( 'model:document' ) // return true
*
* See also {@link module:engine/model/node~Node#is `Node#is()`} for some more details related to elements.
*
* @param {String} type
* @returns {Boolean}
*/
is( type ) {
return type == 'model';
}

/**
* Common part of {@link module:engine/model/model~Model#change} and {@link module:engine/model/model~Model#enqueueChange}
* which calls callbacks and returns array of values returned by these callbacks.
Expand Down
6 changes: 4 additions & 2 deletions src/model/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ export default class 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 `model:` to narrow search exclusively to model's objects.
* That should prevent of situation where `view:node` accidentally might be considered as `model:node`.
* Types are defined as name of the class written in [camelCase](https://en.wikipedia.org/wiki/Camel_case) notation.
* E.g. class `LiveRange` will get type `liveRange`.
*
* There is more classes in model which follows similar naming convention. Check corresponding elements documentation for more details.
*
* obj.is( 'node' ); // true for any node, false for document fragment and text fragment
* obj.is( 'documentFragment' ); // true for document fragment, false for any node
Expand All @@ -478,8 +482,6 @@ export default class Node {
* obj.is( 'text' ); // true for text node, false for element and document fragment
* obj.is( 'textProxy' ); // true for text proxy object
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @method #is
* @param {String} type
* @returns {Boolean}
Expand Down
12 changes: 0 additions & 12 deletions src/model/nodelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,6 @@ export default class NodeList {
return this.length;
}

/**
* Checks whether given object is of `nodeList` type.
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @param {String} type
* @returns {Boolean}
*/
is( type ) {
return type == 'nodeList' || type == 'model:nodeList';
}

/**
* Inserts given nodes at given index.
*
Expand Down
2 changes: 1 addition & 1 deletion src/model/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ export default class Position {
/**
* Checks whether given object is of `position` type.
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
* Read more at {@link module:engine/model/model~Node#is `Node#is()`}.
*
* @param {String} type
* @returns {Boolean}
Expand Down
2 changes: 1 addition & 1 deletion src/model/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class Range {
/**
* Checks whether given object is of `range` type.
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
* Read more at {@link module:engine/model/model~Node#is `Node#is()`}.
*
* @param {String} type
* @returns {Boolean}
Expand Down
12 changes: 0 additions & 12 deletions src/model/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,6 @@ export default class Schema {
return this.getDefinitions()[ itemName ];
}

/**
* Checks whether given object is of `schema` type.
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @param {String} type
* @returns {Boolean}
*/
is( type ) {
return type == 'schema' || type == 'model:schema';
}

/**
* Returns `true` if the given item is registered in the schema.
*
Expand Down
2 changes: 0 additions & 2 deletions src/model/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,6 @@ export default class Selection {
* selection.is( 'element' ); // false
* selection.is( 'view:selection' ); // false
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @param {String} type
* @returns {Boolean}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/model/textproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default class TextProxy {
/**
* Checks whether given object is of `textProxy` type.
*
* Read more in {@link module:engine/model/node~Node#is `Node#is()`} and {@link module:engine/model/model~Model#is `Model#is()`}.
* Read more in {@link module:engine/model/node~Node#is `Node#is()`}.
*
* @param {String} type
* @returns {Boolean}
Expand Down
12 changes: 0 additions & 12 deletions src/model/treewalker.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,6 @@ export default class TreeWalker {
this._visitedParent = this.position.parent;
}

/**
* Checks whether given object is of `treeWalker` type.
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @param {String} type
* @returns {Boolean}
*/
is( type ) {
return type == 'treeWalker' || type == 'model:treeWalker';
}

/**
* Iterable interface.
*
Expand Down
12 changes: 0 additions & 12 deletions src/model/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@ export default class Writer {
this.batch = batch;
}

/**
* Checks whether given object is of `writer` type.
*
* Read more at {@link module:engine/model/model~Model#is `Model#is()`}.
*
* @param {String} type
* @returns {Boolean}
*/
is( type ) {
return type == 'writer' || type == 'model:writer';
}

/**
* Creates a new {@link module:engine/model/text~Text text node}.
*
Expand Down

0 comments on commit f8f14eb

Please sign in to comment.