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

Commit

Permalink
Update docs for View, and replace trig with regexp in is() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Samsel committed Jul 26, 2019
1 parent 0fb8821 commit 3aa2407
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/view/containerelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class ContainerElement extends Element {
* @inheritDoc
*/
is( type, name = null ) {
const cutType = type && type.replace( 'view:', '' );
const cutType = type && type.replace( /^view:/, '' );
if ( !name ) {
return cutType == 'containerElement' || super.is( type );
} else {
Expand Down
10 changes: 8 additions & 2 deletions src/view/documentfragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ export default class DocumentFragment {
}

/**
* Checks whether given view tree object is of given type following the convention set by
* {@link module:engine/view/node~Node#is `Node#is()`}.
* Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string,
* for example `view:documentFragment`. Type is a string which usually equal to a name of the class written in camelCase convention.
* If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true`
* for any type match for an entire child-parent chain.
*
* Acceptable type for this class is `documentFragment` and its prefixed version.
*
* See also: {@link module:engine/view/node~Node#is `Node#is()`}.
*
* @param {String} type
* @returns {Boolean}
Expand Down
21 changes: 8 additions & 13 deletions src/view/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,14 @@ export default class DocumentSelection {
}

/**
* Checks whether object is of given type following the convention set by
* {@link module:engine/view/node~Node#is `Node#is()`}.
*
* const selection = new DocumentSelection( ... );
*
* selection.is( 'selection' ); // true
* selection.is( 'view:selection' ); // true
* selection.is( 'documentSelection' ); // true
* selection.is( 'view:documentSelection' ); // true
* selection.is( 'node' ); // false
* selection.is( 'view:node' ); // false
* selection.is( 'model:selection' ); // false
* selection.is( 'element' ); // false
* Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string,
* for example `view:selection`. Type is a string which usually equal to a name of the class written in camelCase convention.
* If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true`
* for any type match for an entire child-parent chain.
*
* Acceptable types for this class are `selection` and `documentSelection` and its prefixed version.
*
* See also: {@link module:engine/view/node~Node#is `Node#is()`}.
*
* @param {String} type
* @returns {Boolean}
Expand Down
2 changes: 1 addition & 1 deletion src/view/editableelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class EditableElement extends ContainerElement {
* @inheritDoc
*/
is( type, name = null ) {
const cutType = type && type.replace( 'view:', '' );
const cutType = type && type.replace( /^view:/, '' );
if ( !name ) {
return cutType == 'editableElement' || super.is( type );
} else {
Expand Down
16 changes: 13 additions & 3 deletions src/view/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,32 @@ export default class Element extends Node {
}

/**
* Checks whether this view object is of the given type.
* Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string,
* for example `view:element`. Type is a string which usually equal to a name of the class written in camelCase convention.
* If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true`
* for any type match for an entire child-parent chain.
*
* There is also possibility to check element's {@link #name} rather than just type. Name might be provided as second attribute
* or might replace the type.
*
* // obj is a `li` element
* obj.is( 'element' ); // true
* obj.is( 'view:element' ); // true
* obj.is( 'li' ); // true
* obj.is( 'element', 'li' ); // true
* obj.is( 'text' ); // false
* obj.is( 'element', 'img' ); // false
*
* Read more in {@link module:engine/view/node~Node#is `Node#is()`}.
* Acceptable type for this class is `element` and its prefixed version, element's name or combination of both arguments.
*
* See also: {@link module:engine/view/node~Node#is `Node#is()`}.
*
* @param {String} type
* @param {String} [name] Element name.
* @returns {Boolean}
*/
is( type, name = null ) {
const cutType = type.replace( 'view:', '' );
const cutType = type.replace( /^view:/, '' );
if ( !name ) {
return cutType == 'element' || cutType == this.name || super.is( type );
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/view/emptyelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class EmptyElement extends Element {
* @inheritDoc
*/
is( type, name = null ) {
const cutType = type.replace( 'view:', '' );
const cutType = type.replace( /^view:/, '' );
if ( !name ) {
return cutType == 'emptyElement' || super.is( type );
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/view/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ export default class Node {
* obj.is( 'view:text' ); // true for text node, false for element and document fragment
*
*
* Acceptable types for this class is `node` and its prefixed version.
*
* @param {String} type
* @returns {Boolean}
*/
Expand Down
10 changes: 8 additions & 2 deletions src/view/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,14 @@ export default class Position {
}

/**
* Checks whether given object is of `position` type following the convention set by
* {@link module:engine/view/node~Node#is `Node#is()`}.
* Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string,
* for example `view:position`. Type is a string which usually equal to a name of the class written in camelCase convention.
* If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true`
* for any type match for an entire child-parent chain.
*
* Acceptable type for this class is `position` and its prefixed version.
*
* See also: {@link module:engine/view/node~Node#is `Node#is()`}.
*
* @param {String} type
* @returns {Boolean}
Expand Down
10 changes: 8 additions & 2 deletions src/view/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,14 @@ export default class Range {
}

/**
* Checks whether given object is of `range` type following the convention set by
* {@link module:engine/view/node~Node#is `Node#is()`}.
* Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string,
* for example `view:range`. Type is a string which usually equal to a name of the class written in camelCase convention.
* If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true`
* for any type match for an entire child-parent chain.
*
* Acceptable type for this class is `range` and its prefixed version.
*
* See also: {@link module:engine/view/node~Node#is `Node#is()`}.
*
* @param {String} type
* @returns {Boolean}
Expand Down
2 changes: 1 addition & 1 deletion src/view/rooteditableelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class RootEditableElement extends EditableElement {
* @inheritDoc
*/
is( type, name = null ) {
const cutType = type.replace( 'view:', '' );
const cutType = type.replace( /^view:/, '' );
if ( !name ) {
return cutType == 'rootElement' || super.is( type );
} else {
Expand Down
11 changes: 9 additions & 2 deletions src/view/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,22 @@ export default class Selection {
}

/**
* Checks whether object is of given type following the convention set by
* {@link module:engine/view/node~Node#is `Node#is()`}.
* Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string,
* for example `view:selection`. Type is a string which usually equal to a name of the class written in camelCase convention.
* If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true`
* for any type match for an entire child-parent chain.
*
* const selection = new Selection( ... );
*
* selection.is( 'selection' ); // true
* selection.is( 'view:selection' ); // true
* selection.is( 'node' ); // false
* selection.is( 'element' ); // false
*
* Acceptable type for this class is `selection` and its prefixed version.
*
* See also: {@link module:engine/view/node~Node#is `Node#is()`}.
*
* @param {String} type
* @returns {Boolean}
Expand Down
10 changes: 8 additions & 2 deletions src/view/textproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,14 @@ export default class TextProxy {
}

/**
* Checks whether given view tree object is of given type following the convention set by
* {@link module:engine/view/node~Node#is `Node#is()`}.
* Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string,
* for example `view:textProxy`. Type is a string which usually equal to a name of the class written in camelCase convention.
* If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true`
* for any type match for an entire child-parent chain.
*
* Acceptable type for this class is `textProxy` and its prefixed version.
*
* See also: {@link module:engine/view/node~Node#is `Node#is()`}.
*
* @param {String} type
* @returns {Boolean}
Expand Down
2 changes: 1 addition & 1 deletion src/view/uielement.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class UIElement extends Element {
* @inheritDoc
*/
is( type, name = null ) {
const cutType = type.replace( 'view:', '' );
const cutType = type.replace( /^view:/, '' );
if ( !name ) {
return cutType == 'uiElement' || super.is( type );
} else {
Expand Down

0 comments on commit 3aa2407

Please sign in to comment.