From c5899e0955b620d19fad132e0e0ec75d84450420 Mon Sep 17 00:00:00 2001 From: Junsik Shim Date: Tue, 27 Apr 2021 21:40:09 +0900 Subject: [PATCH] - Removed mxUtils.indexOf(). --- .../model/mxGraphHierarchyModel.js | 15 ++--------- .../hierarchical/model/mxSwimlaneModel.js | 14 ++-------- .../src/serialization/mxChildChangeCodec.js | 3 +-- .../core/src/serialization/mxObjectCodec.js | 4 +-- packages/core/src/shape/mxShape.ts | 2 +- packages/core/src/util/mxResources.js | 2 +- packages/core/src/util/mxUtils.js | 27 ++----------------- packages/core/src/view/cell/mxCell.ts | 8 +++--- packages/core/src/view/cell/mxCellRenderer.ts | 2 +- packages/core/src/view/graph/mxGraph.ts | 8 +++--- .../src/view/graph/mxGraphSelectionModel.ts | 4 +-- packages/html/stories/Clipboard.stories.js | 8 +++--- 12 files changed, 26 insertions(+), 71 deletions(-) diff --git a/packages/core/src/layout/hierarchical/model/mxGraphHierarchyModel.js b/packages/core/src/layout/hierarchical/model/mxGraphHierarchyModel.js index 08770dd21..1f1d8b426 100644 --- a/packages/core/src/layout/hierarchical/model/mxGraphHierarchyModel.js +++ b/packages/core/src/layout/hierarchical/model/mxGraphHierarchyModel.js @@ -8,7 +8,6 @@ import mxDictionary from '../../../util/datatypes/mxDictionary'; import mxGraphHierarchyNode from './mxGraphHierarchyNode'; import mxGraphHierarchyEdge from './mxGraphHierarchyEdge'; -import mxUtils from '../../../util/mxUtils'; /** * Class: mxGraphHierarchyModel @@ -94,12 +93,7 @@ class mxGraphHierarchyModel { internalTargetCell.connectsAsTarget = []; } - if ( - mxUtils.indexOf( - internalTargetCell.connectsAsTarget, - internalEdge - ) < 0 - ) { + if (internalTargetCell.connectsAsTarget.indexOf(internalEdge) < 0) { internalTargetCell.connectsAsTarget.push(internalEdge); } } @@ -259,12 +253,7 @@ class mxGraphHierarchyModel { internalEdge.source = internalVertices[i]; - if ( - mxUtils.indexOf( - internalVertices[i].connectsAsSource, - internalEdge - ) < 0 - ) { + if (internalVertices[i].connectsAsSource.indexOf(internalEdge) < 0) { internalVertices[i].connectsAsSource.push(internalEdge); } } diff --git a/packages/core/src/layout/hierarchical/model/mxSwimlaneModel.js b/packages/core/src/layout/hierarchical/model/mxSwimlaneModel.js index 2f7c2e53b..93f5a69da 100644 --- a/packages/core/src/layout/hierarchical/model/mxSwimlaneModel.js +++ b/packages/core/src/layout/hierarchical/model/mxSwimlaneModel.js @@ -93,12 +93,7 @@ class mxSwimlaneModel { internalTargetCell.connectsAsTarget = []; } - if ( - mxUtils.indexOf( - internalTargetCell.connectsAsTarget, - internalEdge - ) < 0 - ) { + if (internalTargetCell.connectsAsTarget.indexOf(internalEdge) < 0) { internalTargetCell.connectsAsTarget.push(internalEdge); } } @@ -274,12 +269,7 @@ class mxSwimlaneModel { internalEdge.source = internalVertices[i]; - if ( - mxUtils.indexOf( - internalVertices[i].connectsAsSource, - internalEdge - ) < 0 - ) { + if (internalVertices[i].connectsAsSource.indexOf(internalEdge) < 0) { internalVertices[i].connectsAsSource.push(internalEdge); } } diff --git a/packages/core/src/serialization/mxChildChangeCodec.js b/packages/core/src/serialization/mxChildChangeCodec.js index d19e472c9..de38042ca 100644 --- a/packages/core/src/serialization/mxChildChangeCodec.js +++ b/packages/core/src/serialization/mxChildChangeCodec.js @@ -8,7 +8,6 @@ import mxChildChange from '../atomic_changes/mxChildChange'; import mxObjectCodec from './mxObjectCodec'; import mxCodecRegistry from './mxCodecRegistry'; -import mxUtils from '../util/mxUtils'; import mxConstants from '../util/mxConstants'; /** @@ -50,7 +49,7 @@ class mxChildChangeCodec extends mxObjectCodec { if (attr === 'child' && (!isWrite || obj.model.contains(obj.previous))) { return true; } - return mxUtils.indexOf(this.idrefs, attr) >= 0; + return this.idrefs.indexOf(attr) >= 0; } /** diff --git a/packages/core/src/serialization/mxObjectCodec.js b/packages/core/src/serialization/mxObjectCodec.js index 85c9d5cf4..68af98594 100644 --- a/packages/core/src/serialization/mxObjectCodec.js +++ b/packages/core/src/serialization/mxObjectCodec.js @@ -314,7 +314,7 @@ class mxObjectCodec { isExcluded(obj, attr, value, write) { return ( attr == mxObjectIdentity.FIELD_NAME || - mxUtils.indexOf(this.exclude, attr) >= 0 + this.exclude.indexOf(attr) >= 0 ); } @@ -331,7 +331,7 @@ class mxObjectCodec { */ // isReference(obj: any, attr: string, value: any, write?: boolean): boolean; isReference(obj, attr, value, write) { - return mxUtils.indexOf(this.idrefs, attr) >= 0; + return this.idrefs.indexOf(attr) >= 0; } /** diff --git a/packages/core/src/shape/mxShape.ts b/packages/core/src/shape/mxShape.ts index 677483070..805087669 100644 --- a/packages/core/src/shape/mxShape.ts +++ b/packages/core/src/shape/mxShape.ts @@ -1045,7 +1045,7 @@ class mxShape { if ( rounded && (dx !== 0 || dy !== 0) && - (exclude == null || mxUtils.indexOf(exclude, i - 1) < 0) + (exclude == null || exclude.indexOf(i - 1) < 0) ) { // Draws a line from the last point to the current // point with a spacing of size off the current point diff --git a/packages/core/src/util/mxResources.js b/packages/core/src/util/mxResources.js index 189d3751a..3fafa09ab 100644 --- a/packages/core/src/util/mxResources.js +++ b/packages/core/src/util/mxResources.js @@ -109,7 +109,7 @@ const mxResources = { */ isLanguageSupported: lan => { if (mxClient.languages != null) { - return mxUtils.indexOf(mxClient.languages, lan) >= 0; + return mxClient.languages.indexOf(lan) >= 0; } return true; diff --git a/packages/core/src/util/mxUtils.js b/packages/core/src/util/mxUtils.js index 446b28040..ad6dc12af 100644 --- a/packages/core/src/util/mxUtils.js +++ b/packages/core/src/util/mxUtils.js @@ -189,29 +189,6 @@ const mxUtils = { return null; }, - /** - * Function: indexOf - * - * Returns the index of obj in array or -1 if the array does not contain - * the given object. - * - * Parameters: - * - * array - Array to check for the given obj. - * obj - Object to find in the given array. - */ - indexOf: (array, obj) => { - if (array != null && obj != null) { - for (let i = 0; i < array.length; i += 1) { - if (array[i] == obj) { - return i; - } - } - } - - return -1; - }, - /** * Function: forEach * @@ -254,12 +231,12 @@ const mxUtils = { let result = null; if (typeof array === 'object') { - let index = mxUtils.indexOf(array, obj); + let index = array.indexOf(obj); while (index >= 0) { array.splice(index, 1); result = obj; - index = mxUtils.indexOf(array, obj); + index = array.indexOf(obj); } } diff --git a/packages/core/src/view/cell/mxCell.ts b/packages/core/src/view/cell/mxCell.ts index c1164604e..ad2192609 100644 --- a/packages/core/src/view/cell/mxCell.ts +++ b/packages/core/src/view/cell/mxCell.ts @@ -438,7 +438,8 @@ class mxCell { */ // getIndex(child: mxCell): number; getIndex(child: mxCell | null): number { - return mxUtils.indexOf(this.children, child); + if (child === null || !this.children) return -1; + return this.children.indexOf(child); } /** @@ -540,7 +541,8 @@ class mxCell { */ // getEdgeIndex(edge: mxCell): number; getEdgeIndex(edge: mxCell): number { - return mxUtils.indexOf(this.edges, edge); + if (!this.edges) return -1; + return this.edges.indexOf(edge); } /** @@ -573,7 +575,7 @@ class mxCell { if ( this.edges == null || edge.getTerminal(!isOutgoing) !== this || - mxUtils.indexOf(this.edges, edge) < 0 + this.edges.indexOf(edge) < 0 ) { if (this.edges == null) { this.edges = []; diff --git a/packages/core/src/view/cell/mxCellRenderer.ts b/packages/core/src/view/cell/mxCellRenderer.ts index 2f08f29a2..29263bd8f 100644 --- a/packages/core/src/view/cell/mxCellRenderer.ts +++ b/packages/core/src/view/cell/mxCellRenderer.ts @@ -316,7 +316,7 @@ class mxCellRenderer { ]; for (let i = 0; i < styles.length; i += 1) { - if (mxUtils.indexOf(values, state.style[styles[i]]) >= 0) { + if (values.indexOf(state.style[styles[i]]) >= 0) { return true; } } diff --git a/packages/core/src/view/graph/mxGraph.ts b/packages/core/src/view/graph/mxGraph.ts index 3efe7ea88..e36ee6f0d 100644 --- a/packages/core/src/view/graph/mxGraph.ts +++ b/packages/core/src/view/graph/mxGraph.ts @@ -1511,7 +1511,7 @@ class mxGraph extends mxEventSource { if (overlay == null) { this.removeCellOverlays(cell); } else { - const index = mxUtils.indexOf(cell.overlays, overlay); + const index = cell.overlays ? cell.overlays.indexOf(overlay) : -1; if (index >= 0) { (cell.overlays).splice(index, 1); @@ -6708,7 +6708,7 @@ class mxGraph extends mxEventSource { geo.height ); - if (mxUtils.indexOf(cells, parent) >= 0) { + if (cells.indexOf(parent) >= 0) { bbox.x += tmp.x; bbox.y += tmp.y; } @@ -6719,7 +6719,7 @@ class mxGraph extends mxEventSource { if ( parent.isVertex() && - mxUtils.indexOf(cells, parent) >= 0 + cells.indexOf(parent) >= 0 ) { tmp = this.getBoundingBoxFromGeometry([parent], false); @@ -9766,7 +9766,7 @@ class mxGraph extends mxEventSource { // Checks if parent is dropped into child if not cloning if (!clone) { let parent = cell; - while (parent != null && mxUtils.indexOf(cells, parent) < 0) { + while (parent != null && cells.indexOf(parent) < 0) { parent = parent.getParent(); } } diff --git a/packages/core/src/view/graph/mxGraphSelectionModel.ts b/packages/core/src/view/graph/mxGraphSelectionModel.ts index 1b7fc5867..e6e9f9619 100644 --- a/packages/core/src/view/graph/mxGraphSelectionModel.ts +++ b/packages/core/src/view/graph/mxGraphSelectionModel.ts @@ -113,7 +113,7 @@ class mxGraphSelectionModel extends mxEventSource { // isSelected(cell: mxCell): boolean; isSelected(cell: mxCell): boolean { if (cell != null) { - return mxUtils.indexOf(this.cells, cell) >= 0; + return this.cells.indexOf(cell) >= 0; } return false; } @@ -302,7 +302,7 @@ class mxGraphSelectionModel extends mxEventSource { // cellRemoved(cell: mxCell): void; cellRemoved(cell: mxCell): void { if (cell != null) { - const index = mxUtils.indexOf(this.cells, cell); + const index = this.cells.indexOf(cell); if (index >= 0) { this.cells.splice(index, 1); } diff --git a/packages/html/stories/Clipboard.stories.js b/packages/html/stories/Clipboard.stories.js index cc10ce345..546922cd0 100644 --- a/packages/html/stories/Clipboard.stories.js +++ b/packages/html/stories/Clipboard.stories.js @@ -282,15 +282,13 @@ const Template = ({ label, ...args }) => { if (provider != null) { data = - mxUtils.indexOf(provider.types, 'text/html') >= 0 + provider.types.indexOf('text/html') >= 0 ? provider.getData('text/html') : null; if ( - mxUtils.indexOf( - provider.types, - 'text/plain' && (data == null || data.length === 0) - ) + provider.types.indexOf('text/plain') + && (data == null || data.length === 0) ) { data = provider.getData('text/plain'); }