- Removed mxUtils.bind().

development
Junsik Shim 2021-04-27 21:23:17 +09:00
parent cf437a9b6f
commit 654736d23d
18 changed files with 71 additions and 82 deletions

View File

@ -104,11 +104,11 @@ class mxDefaultToolbar {
}); });
// Resets the selected tool after a doubleclick or escape keystroke // Resets the selected tool after a doubleclick or escape keystroke
this.resetHandler = mxUtils.bind(this, () => { this.resetHandler = () => {
if (this.toolbar != null) { if (this.toolbar != null) {
this.toolbar.resetMode(true); this.toolbar.resetMode(true);
} }
}); };
this.editor.graph.addListener(mxEvent.DOUBLE_CLICK, this.resetHandler); this.editor.graph.addListener(mxEvent.DOUBLE_CLICK, this.resetHandler);
this.editor.addListener(mxEvent.ESCAPE, this.resetHandler); this.editor.addListener(mxEvent.ESCAPE, this.resetHandler);
@ -176,9 +176,9 @@ class mxDefaultToolbar {
*/ */
// addActionOption(combo: HTMLElement, title: string, action: string): void; // addActionOption(combo: HTMLElement, title: string, action: string): void;
addActionOption(combo, title, action) { addActionOption(combo, title, action) {
const clickHandler = mxUtils.bind(this, () => { const clickHandler = () => {
this.editor.execute(action); this.editor.execute(action);
}); };
this.addOption(combo, title, clickHandler); this.addOption(combo, title, clickHandler);
} }
@ -241,7 +241,7 @@ class mxDefaultToolbar {
addPrototype(title, icon, ptype, pressed, insert, toggle) { addPrototype(title, icon, ptype, pressed, insert, toggle) {
// Creates a wrapper function that is in charge of constructing // Creates a wrapper function that is in charge of constructing
// the new cell instance to be inserted into the graph // the new cell instance to be inserted into the graph
const factory = mxUtils.bind(this, () => { const factory = () => {
if (typeof ptype === 'function') { if (typeof ptype === 'function') {
return ptype(); return ptype();
} }
@ -250,7 +250,7 @@ class mxDefaultToolbar {
} }
return null; return null;
}); };
// Defines the function for a click event on the graph // Defines the function for a click event on the graph
// after this item has been selected in the toolbar // after this item has been selected in the toolbar
@ -428,7 +428,7 @@ class mxDefaultToolbar {
sprite.setAttribute('src', img.getAttribute('src')); sprite.setAttribute('src', img.getAttribute('src'));
// Handles delayed loading of the images // Handles delayed loading of the images
const loader = mxUtils.bind(this, evt => { const loader = evt => {
// Preview uses the image node with double size. Later this can be // Preview uses the image node with double size. Later this can be
// changed to use a separate preview and guides, but for this the // changed to use a separate preview and guides, but for this the
// dropHandler must use the additional x- and y-arguments and the // dropHandler must use the additional x- and y-arguments and the
@ -439,7 +439,7 @@ class mxDefaultToolbar {
makeDraggable(img, this.editor.graph, dropHandler, sprite); makeDraggable(img, this.editor.graph, dropHandler, sprite);
mxEvent.removeListener(sprite, 'load', loader); mxEvent.removeListener(sprite, 'load', loader);
}); };
} }
/** /**

View File

@ -1529,9 +1529,9 @@ class mxEditor extends mxEventSource {
createSwimlaneManager(graph) { createSwimlaneManager(graph) {
const swimlaneMgr = new mxSwimlaneManager(graph, false); const swimlaneMgr = new mxSwimlaneManager(graph, false);
swimlaneMgr.isHorizontal = mxUtils.bind(this, () => { swimlaneMgr.isHorizontal = () => {
return this.horizontalFlow; return this.horizontalFlow;
}); };
swimlaneMgr.isEnabled = () => { swimlaneMgr.isEnabled = () => {
return this.maintainSwimlanes; return this.maintainSwimlanes;
@ -1621,15 +1621,15 @@ class mxEditor extends mxEventSource {
// Installs a listener for double click events // Installs a listener for double click events
graph.addListener( graph.addListener(
mxEvent.DOUBLE_CLICK, mxEvent.DOUBLE_CLICK,
mxUtils.bind(this, (sender, evt) => { (sender, evt) => {
const cell = evt.getProperty('cell'); const cell = evt.getProperty('cell');
if (cell != null && graph.isEnabled() && this.dblClickAction != null) { if (cell != null && graph.isEnabled() && this.dblClickAction != null) {
this.execute(this.dblClickAction, cell); this.execute(this.dblClickAction, cell);
evt.consume(); evt.consume();
} }
}) }
); )
} }
/** /**
@ -1662,9 +1662,9 @@ class mxEditor extends mxEventSource {
*/ */
// installDrillHandler(graph: any): void; // installDrillHandler(graph: any): void;
installDrillHandler(graph) { installDrillHandler(graph) {
const listener = mxUtils.bind(this, sender => { const listener = sender => {
this.fireEvent(new mxEventObject(mxEvent.ROOT)); this.fireEvent(new mxEventObject(mxEvent.ROOT));
}); };
graph.getView().addListener(mxEvent.DOWN, listener); graph.getView().addListener(mxEvent.DOWN, listener);
graph.getView().addListener(mxEvent.UP, listener); graph.getView().addListener(mxEvent.UP, listener);
@ -1819,13 +1819,13 @@ class mxEditor extends mxEventSource {
// when files are saved // when files are saved
this.addListener( this.addListener(
mxEvent.SAVE, mxEvent.SAVE,
mxUtils.bind(this, () => { () => {
const tstamp = new Date().toLocaleString(); const tstamp = new Date().toLocaleString();
this.setStatus( this.setStatus(
`${mxResources.get(this.lastSavedResource) || `${mxResources.get(this.lastSavedResource) ||
this.lastSavedResource}: ${tstamp}` this.lastSavedResource}: ${tstamp}`
); );
}) }
); );
// Updates the statusbar to display the filename // Updates the statusbar to display the filename
@ -1859,9 +1859,9 @@ class mxEditor extends mxEventSource {
setTitleContainer(container) { setTitleContainer(container) {
this.addListener( this.addListener(
mxEvent.ROOT, mxEvent.ROOT,
mxUtils.bind(this, sender => { sender => {
container.innerHTML = this.getTitle(); container.innerHTML = this.getTitle();
}) }
); );
} }
@ -2286,7 +2286,7 @@ class mxEditor extends mxEventSource {
// Defines the function to be executed when the // Defines the function to be executed when the
// OK button is pressed in the dialog // OK button is pressed in the dialog
const okFunction = mxUtils.bind(this, () => { const okFunction = () => {
// Hides the dialog // Hides the dialog
this.hideProperties(); this.hideProperties();
@ -2335,7 +2335,7 @@ class mxEditor extends mxEventSource {
} finally { } finally {
model.endUpdate(); model.endUpdate();
} }
}); };
// Defines the function to be executed when the // Defines the function to be executed when the
// Cancel button is pressed in the dialog // Cancel button is pressed in the dialog
@ -2404,11 +2404,11 @@ class mxEditor extends mxEventSource {
// Installs a function to update the contents // Installs a function to update the contents
// of the tasks window on every change of the // of the tasks window on every change of the
// model, selection or root. // model, selection or root.
const funct = mxUtils.bind(this, sender => { const funct = sender => {
mxEvent.release(div); mxEvent.release(div);
div.innerHTML = ''; div.innerHTML = '';
this.createTasks(div); this.createTasks(div);
}); };
this.graph.getModel().addListener(mxEvent.CHANGE, funct); this.graph.getModel().addListener(mxEvent.CHANGE, funct);
this.graph.getSelectionModel().addListener(mxEvent.CHANGE, funct); this.graph.getSelectionModel().addListener(mxEvent.CHANGE, funct);

View File

@ -528,7 +528,7 @@ class mxConnectionHandler extends mxEventSource {
this.constraintHandler = new mxConstraintHandler(this.graph); this.constraintHandler = new mxConstraintHandler(this.graph);
// Redraws the icons if the graph changes // Redraws the icons if the graph changes
this.changeHandler = mxUtils.bind(this, sender => { this.changeHandler = sender => {
if (this.iconState != null) { if (this.iconState != null) {
this.iconState = this.graph.getView().getState(this.iconState.cell); this.iconState = this.graph.getView().getState(this.iconState.cell);
} }
@ -542,7 +542,7 @@ class mxConnectionHandler extends mxEventSource {
) { ) {
this.reset(); this.reset();
} }
}); };
this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler); this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler);
this.graph.getView().addListener(mxEvent.SCALE, this.changeHandler); this.graph.getView().addListener(mxEvent.SCALE, this.changeHandler);

View File

@ -232,9 +232,9 @@ class mxConstraintHandler {
if (this.isEnabled() && !this.isEventIgnored(me)) { if (this.isEnabled() && !this.isEventIgnored(me)) {
// Lazy installation of mouseleave handler // Lazy installation of mouseleave handler
if (this.mouseleaveHandler == null && this.graph.container != null) { if (this.mouseleaveHandler == null && this.graph.container != null) {
this.mouseleaveHandler = mxUtils.bind(this, () => { this.mouseleaveHandler = () => {
this.reset(); this.reset();
}); };
mxEvent.addListener( mxEvent.addListener(
this.graph.container, this.graph.container,
@ -444,9 +444,9 @@ class mxConstraintHandler {
); );
} }
const getState = mxUtils.bind(this, () => { const getState = () => {
return this.currentFocus != null ? this.currentFocus : state; return this.currentFocus != null ? this.currentFocus : state;
}); };
icon.redraw(); icon.redraw();

View File

@ -741,7 +741,7 @@ class mxEdgeHandler {
if (this.graph.isCellBendable(cell)) { if (this.graph.isCellBendable(cell)) {
for (let i = 1; i < this.abspoints.length; i += 1) { for (let i = 1; i < this.abspoints.length; i += 1) {
mxUtils.bind(this, bend => { (bend => {
this.initBend(bend); this.initBend(bend);
bend.setCursor(mxConstants.CURSOR_VIRTUAL_BEND_HANDLE); bend.setCursor(mxConstants.CURSOR_VIRTUAL_BEND_HANDLE);
bends.push(bend); bends.push(bend);

View File

@ -53,9 +53,9 @@ class mxGraphHandler {
this.graph.addListener(mxEvent.PAN, this.panHandler); this.graph.addListener(mxEvent.PAN, this.panHandler);
// Handles escape keystrokes // Handles escape keystrokes
this.escapeHandler = mxUtils.bind(this, (sender, evt) => { this.escapeHandler = (sender, evt) => {
this.reset(); this.reset();
}); };
this.graph.addListener(mxEvent.ESCAPE, this.escapeHandler); this.graph.addListener(mxEvent.ESCAPE, this.escapeHandler);
@ -68,7 +68,7 @@ class mxGraphHandler {
// Waits for the states and handlers to be updated // Waits for the states and handlers to be updated
this.refreshThread = window.setTimeout( this.refreshThread = window.setTimeout(
mxUtils.bind(this, () => { () => {
this.refreshThread = null; this.refreshThread = null;
if (this.first != null && !this.suspended) { if (this.first != null && !this.suspended) {
@ -101,7 +101,7 @@ class mxGraphHandler {
} }
} }
} }
}), },
0 0
); );
}; };
@ -679,14 +679,14 @@ class mxGraphHandler {
const parent = this.graph.getDefaultParent(); const parent = this.graph.getDefaultParent();
const model = this.graph.getModel(); const model = this.graph.getModel();
const filter = mxUtils.bind(this, cell => { const filter = cell => {
return ( return (
this.graph.view.getState(cell) != null && this.graph.view.getState(cell) != null &&
cell.isVertex() && cell.isVertex() &&
cell.getGeometry() != null && cell.getGeometry() != null &&
!cell.getGeometry().relative !cell.getGeometry().relative
); );
}); };
return this.graph.view.getCellStates( return this.graph.view.getCellStates(
model.filterDescendants(filter, parent) model.filterDescendants(filter, parent)
@ -1250,7 +1250,7 @@ class mxGraphHandler {
if (this.allCells != null) { if (this.allCells != null) {
this.allCells.visit( this.allCells.visit(
mxUtils.bind(this, (key, state) => { (key, state) => {
const realState = this.graph.view.getState(state.cell); const realState = this.graph.view.getState(state.cell);
// Checks if cell was removed or replaced // Checks if cell was removed or replaced
@ -1324,7 +1324,7 @@ class mxGraphHandler {
} }
} }
} }
}) }
); );
} }

View File

@ -66,7 +66,7 @@ class mxPanningHandler extends mxEventSource {
); );
// Handles pinch gestures // Handles pinch gestures
this.gestureHandler = mxUtils.bind(this, (sender, eo) => { this.gestureHandler = (sender, eo) => {
if (this.isPinchEnabled()) { if (this.isPinchEnabled()) {
const evt = eo.getProperty('event'); const evt = eo.getProperty('event');
@ -86,7 +86,7 @@ class mxPanningHandler extends mxEventSource {
this.zoomGraph(evt); this.zoomGraph(evt);
} }
} }
}); };
this.graph.addListener(mxEvent.GESTURE, this.gestureHandler); this.graph.addListener(mxEvent.GESTURE, this.gestureHandler);

View File

@ -110,9 +110,9 @@ class mxPopupMenuHandler extends mxPopupMenu {
// the context menu // the context menu
mxEvent.addGestureListeners( mxEvent.addGestureListeners(
this.div, this.div,
mxUtils.bind(this, evt => { evt => {
this.graph.tooltipHandler.hide(); this.graph.tooltipHandler.hide();
}) }
); );
} }

View File

@ -44,9 +44,9 @@ class mxRubberband {
); );
// Repaints the marquee after autoscroll // Repaints the marquee after autoscroll
this.panHandler = mxUtils.bind(this, () => { this.panHandler = () => {
this.repaint(); this.repaint();
}); };
this.graph.addListener(mxEvent.PAN, this.panHandler); this.graph.addListener(mxEvent.PAN, this.panHandler);
@ -185,9 +185,9 @@ class mxRubberband {
return me; return me;
} }
this.dragHandler = mxUtils.bind(this, evt => { this.dragHandler = evt => {
this.mouseMove(this.graph, createMouseEvent(evt)); this.mouseMove(this.graph, createMouseEvent(evt));
}); };
this.dropHandler = evt => { this.dropHandler = evt => {
this.mouseUp(this.graph, createMouseEvent(evt)); this.mouseUp(this.graph, createMouseEvent(evt));

View File

@ -201,12 +201,12 @@ class mxSelectionCellsHandler extends mxEventSource {
// Destroys unused handlers // Destroys unused handlers
oldHandlers.visit( oldHandlers.visit(
mxUtils.bind(this, (key, handler) => { (key, handler) => {
this.fireEvent( this.fireEvent(
new mxEventObject(mxEvent.REMOVE, 'state', handler.state) new mxEventObject(mxEvent.REMOVE, 'state', handler.state)
); );
handler.destroy(); handler.destroy();
}) }
); );
// Creates new handlers and updates parent highlight on existing handlers // Creates new handlers and updates parent highlight on existing handlers

View File

@ -163,17 +163,6 @@ const mxUtils = {
); );
}, },
/**
* Function: bind
*
* Returns a wrapper function that locks the execution scope of the given
* function to the specified scope. Inside funct, the "this" keyword
* becomes a reference to that scope.
*/
bind: (scope, funct) => {
return funct.bind(scope);
},
/** /**
* Function: findNode * Function: findNode
* *

View File

@ -933,9 +933,9 @@ class mxCellEditor {
state.style[mxConstants.STYLE_OVERFLOW] !== 'fill') state.style[mxConstants.STYLE_OVERFLOW] !== 'fill')
) { ) {
window.setTimeout( window.setTimeout(
mxUtils.bind(this, () => { () => {
this.resize(); this.resize();
}), },
0 0
); );
} }

View File

@ -4145,7 +4145,7 @@ class mxGraph extends mxEventSource {
// Disconnects edges which are not being removed // Disconnects edges which are not being removed
const edges = this.getAllEdges([cells[i]]); const edges = this.getAllEdges([cells[i]]);
const disconnectTerminal = mxUtils.bind(this, (edge: mxCell, source: boolean) => { const disconnectTerminal = (edge: mxCell, source: boolean) => {
let geo = edge.getGeometry(); let geo = edge.getGeometry();
if (geo != null) { if (geo != null) {
@ -4200,7 +4200,7 @@ class mxGraph extends mxEventSource {
this.getModel().setTerminal(edge, null, source); this.getModel().setTerminal(edge, null, source);
} }
} }
}); };
for (let j = 0; j < edges.length; j++) { for (let j = 0; j < edges.length; j++) {
if (!dict.get(edges[j])) { if (!dict.get(edges[j])) {
@ -11549,7 +11549,7 @@ class mxGraph extends mxEventSource {
} }
this.tapAndHoldThread = window.setTimeout( this.tapAndHoldThread = window.setTimeout(
mxUtils.bind(this, handler), handler,
this.tapAndHoldDelay this.tapAndHoldDelay
); );
this.tapAndHoldValid = true; this.tapAndHoldValid = true;

View File

@ -82,11 +82,11 @@ class mxOutline {
// Do not repaint when suspended // Do not repaint when suspended
const outlineGraphModelChanged = this.outline.graphModelChanged; const outlineGraphModelChanged = this.outline.graphModelChanged;
this.outline.graphModelChanged = mxUtils.bind(this, (changes: any) => { this.outline.graphModelChanged = (changes: any) => {
if (!this.suspended && this.outline != null) { if (!this.suspended && this.outline != null) {
outlineGraphModelChanged.apply(this.outline, [changes]); outlineGraphModelChanged.apply(this.outline, [changes]);
} }
}); };
// Enable faster painting in SVG // Enable faster painting in SVG
//const node = <SVGElement>this.outline.getView().getCanvas().parentNode; //const node = <SVGElement>this.outline.getView().getCanvas().parentNode;

View File

@ -563,13 +563,13 @@ class mxPrintPreview {
this.pageFormat.height, this.pageFormat.height,
0, 0,
0, 0,
mxUtils.bind(this, div => { div => {
this.addGraphFragment(-dx, -dy, this.scale, pageNum, div, clip); this.addGraphFragment(-dx, -dy, this.scale, pageNum, div, clip);
if (this.printBackgroundImage) { if (this.printBackgroundImage) {
this.insertBackgroundImage(div, -dx, -dy); this.insertBackgroundImage(div, -dx, -dy);
} }
}), },
pageNum pageNum
); );

View File

@ -37,17 +37,17 @@ class mxSwimlaneManager extends mxEventSource {
this.addEnabled = addEnabled; this.addEnabled = addEnabled;
this.resizeEnabled = resizeEnabled; this.resizeEnabled = resizeEnabled;
this.addHandler = mxUtils.bind(this, (sender: any, evt: mxEventObject) => { this.addHandler = (sender: any, evt: mxEventObject) => {
if (this.isEnabled() && this.isAddEnabled()) { if (this.isEnabled() && this.isAddEnabled()) {
this.cellsAdded(evt.getProperty('cells')); this.cellsAdded(evt.getProperty('cells'));
} }
}); };
this.resizeHandler = mxUtils.bind(this, (sender: any, evt: mxEventObject) => { this.resizeHandler = (sender: any, evt: mxEventObject) => {
if (this.isEnabled() && this.isResizeEnabled()) { if (this.isEnabled() && this.isResizeEnabled()) {
this.cellsResized(evt.getProperty('cells')); this.cellsResized(evt.getProperty('cells'));
} }
}); };
this.setGraph(graph); this.setGraph(graph);
} }

View File

@ -156,7 +156,7 @@ const Template = ({ label, ...args }) => {
mxEvent.addListener( mxEvent.addListener(
textInput, textInput,
'copy', 'copy',
mxUtils.bind(this, function(evt) { (evt) => {
if (graph.isEnabled() && !graph.isSelectionEmpty()) { if (graph.isEnabled() && !graph.isSelectionEmpty()) {
copyCells( copyCells(
graph, graph,
@ -167,20 +167,20 @@ const Template = ({ label, ...args }) => {
dx = 0; dx = 0;
dy = 0; dy = 0;
} }
}) }
); );
// Handles cut event by removing cells putting XML into text input // Handles cut event by removing cells putting XML into text input
mxEvent.addListener( mxEvent.addListener(
textInput, textInput,
'cut', 'cut',
mxUtils.bind(this, function(evt) { (evt) => {
if (graph.isEnabled() && !graph.isSelectionEmpty()) { if (graph.isEnabled() && !graph.isSelectionEmpty()) {
copyCells(graph, graph.removeCells()); copyCells(graph, graph.removeCells());
dx = -gs; dx = -gs;
dy = -gs; dy = -gs;
} }
}) }
); );
// Merges XML into existing graph and layers // Merges XML into existing graph and layers
@ -315,9 +315,9 @@ const Template = ({ label, ...args }) => {
} else { } else {
// Timeout for new value to appear // Timeout for new value to appear
window.setTimeout( window.setTimeout(
mxUtils.bind(this, function() { () => {
pasteText(textInput.value); pasteText(textInput.value);
}), },
0 0
); );
} }

View File

@ -309,9 +309,9 @@ const Template = ({ label, ...args }) => {
overlay.align = mxConstants.ALIGN_CENTER; overlay.align = mxConstants.ALIGN_CENTER;
overlay.addListener( overlay.addListener(
mxEvent.CLICK, mxEvent.CLICK,
mxUtils.bind(this, function(sender, evt) { (sender, evt) => {
addChild(graph, cell); addChild(graph, cell);
}) }
); );
graph.addCellOverlay(cell, overlay); graph.addCellOverlay(cell, overlay);
@ -327,9 +327,9 @@ const Template = ({ label, ...args }) => {
overlay.verticalAlign = mxConstants.ALIGN_TOP; overlay.verticalAlign = mxConstants.ALIGN_TOP;
overlay.addListener( overlay.addListener(
mxEvent.CLICK, mxEvent.CLICK,
mxUtils.bind(this, function(sender, evt) { (sender, evt) => {
deleteSubtree(graph, cell); deleteSubtree(graph, cell);
}) }
); );
graph.addCellOverlay(cell, overlay); graph.addCellOverlay(cell, overlay);