Skip to content

Commit

Permalink
feat(events): use more readable event names
Browse files Browse the repository at this point in the history
re #54
  • Loading branch information
bubkoo committed Dec 24, 2019
1 parent 8f34444 commit e9f3245
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 159 deletions.
3 changes: 2 additions & 1 deletion packages/x6/src/change/selection-change.ts
Expand Up @@ -30,9 +30,10 @@ export class SelectionChange implements IChange {
this.added = this.removed
this.removed = tmp

this.selection.graph.trigger('selectionChanged', {
this.selection.graph.trigger('selection:changed', {
added: this.added,
removed: this.removed,
selected: this.selection.cells.slice(),
})
}
}
2 changes: 1 addition & 1 deletion packages/x6/src/graph/change-manager.ts
Expand Up @@ -37,7 +37,7 @@ export class ChangeManager extends BaseManager {
this.view.translate.x = 0
this.view.translate.y = 0
}
this.graph.trigger('root')
this.graph.trigger('root:changed')
} else if (change instanceof ChildChange) {
const newParent = this.model.getParent(change.child)!
this.view.invalidate(change.child, true, true)
Expand Down
4 changes: 2 additions & 2 deletions packages/x6/src/graph/collapse-manager.ts
Expand Up @@ -29,7 +29,7 @@ export class CollapseManager extends BaseManager {
) {
this.graph.stopEditing(false)
this.model.batchUpdate(() => {
this.graph.trigger('collapseCells', {
this.graph.trigger('cells:collapsing', {
collapsed,
recurse,
cells,
Expand Down Expand Up @@ -68,7 +68,7 @@ export class CollapseManager extends BaseManager {
}
})
})
this.graph.trigger('cellsCollapsed', { cells, collapsed, recurse })
this.graph.trigger('cells:collapsed', { cells, collapsed, recurse })
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/x6/src/graph/connection-manager.ts
Expand Up @@ -13,7 +13,7 @@ export class ConnectionManager extends BaseManager {
) {
this.model.batchUpdate(() => {
const previous = this.model.getTerminal(edge, isSource)
this.graph.trigger('connectCell', {
this.graph.trigger('cell:connecting', {
edge,
terminal,
isSource,
Expand Down Expand Up @@ -63,7 +63,7 @@ export class ConnectionManager extends BaseManager {
this.graph.resetEdge(edge)
}

this.graph.trigger('cellConnected', {
this.graph.trigger('cell:connected', {
edge,
terminal,
isSource,
Expand Down
32 changes: 14 additions & 18 deletions packages/x6/src/graph/creation-manager.ts
Expand Up @@ -98,19 +98,19 @@ export class CreationManager extends BaseManager {
cells: Cell[],
parent: Cell,
index: number,
sourceNode?: Cell,
targetNode?: Cell,
source?: Cell,
target?: Cell,
) {
this.model.batchUpdate(() => {
this.graph.trigger('addCells', {
this.graph.trigger('cells:adding', {
cells,
parent,
index,
sourceNode,
targetNode,
source,
target,
})

this.cellsAdded(cells, parent, index, sourceNode, targetNode, false, true)
this.cellsAdded(cells, parent, index, source, target, false, true)
})

return cells
Expand Down Expand Up @@ -213,12 +213,12 @@ export class CreationManager extends BaseManager {
}
}

this.graph.trigger('cellsAdded', {
this.graph.trigger('cells:added', {
cells,
parent,
index,
sourceNode,
targetNode,
source: sourceNode,
target: targetNode,
absolute: absolute === true,
})
})
Expand Down Expand Up @@ -308,7 +308,7 @@ export class CreationManager extends BaseManager {
}

this.model.batchUpdate(() => {
this.graph.trigger('removeCells', {
this.graph.trigger('cells:removing', {
includeEdges,
cells: removing,
})
Expand Down Expand Up @@ -358,7 +358,7 @@ export class CreationManager extends BaseManager {
this.model.remove(cell)
})

this.graph.trigger('cellsRemoved', { cells })
this.graph.trigger('cells:removed', { cells })
})
}
}
Expand Down Expand Up @@ -457,6 +457,8 @@ export class CreationManager extends BaseManager {
}
}

this.graph.trigger('edge:splitting', { edge, cells, newEdge, dx, dy })

this.graph.movingManager.cellsMoved(cells, dx, dy, false, false)

let index = this.model.getChildCount(parent)
Expand All @@ -466,13 +468,7 @@ export class CreationManager extends BaseManager {
this.cellsAdded([newEdge], parent!, index, source, cells[0], false)
this.graph.connectionManager.cellConnected(edge, cells[0], true)

this.graph.trigger('splitEdge', {
edge,
cells,
newEdge,
dx,
dy,
})
this.graph.trigger('edge:splitted', { edge, cells, newEdge, dx, dy })
})

return newEdge
Expand Down
5 changes: 2 additions & 3 deletions packages/x6/src/graph/editing-accessor.ts
Expand Up @@ -34,7 +34,7 @@ export class EditingAccessor extends BaseGraph {

stopEditing(cancel: boolean = false) {
this.cellEditor.stopEditing(cancel)
this.trigger('editingStopped', { cancel })
this.trigger('cell:edited', { cancel })
return this
}

Expand All @@ -44,9 +44,8 @@ export class EditingAccessor extends BaseGraph {
) {
if (e == null || !DomEvent.isMultiTouchEvent(e)) {
if (cell != null && this.isCellEditable(cell)) {
this.trigger('startEditing', { cell, e })
this.cellEditor.startEditing(cell, e)
this.trigger('editingStarted', { cell, e })
this.trigger('cell:editing', { cell, e })
}
}
return this
Expand Down

0 comments on commit e9f3245

Please sign in to comment.