Skip to content

Commit

Permalink
feat: 增加批量执行命令
Browse files Browse the repository at this point in the history
  • Loading branch information
miyuesc committed Apr 3, 2023
1 parent 377078d commit 876a377
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
19 changes: 19 additions & 0 deletions src/cmd/CommandInitializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type EventBus from 'diagram-js/lib/core/EventBus'
import type CommandStack from 'diagram-js/lib/command/CommandStack'
import type CommandHandler from 'diagram-js/lib/command/CommandHandler'
import MultiCommandHandler from './MultiCommandHandler'

const HANDLERS: Record<string, CommandHandler> = {
'panel.multi-command': MultiCommandHandler
}

export default class CommandInitializer {
static $inject: string[]
constructor(eventBus: EventBus, commandStack: CommandStack) {
eventBus.on('diagram.init', function () {
Object.keys(HANDLERS).forEach((id: string) => commandStack.registerHandler(id, HANDLERS[id]))
})
}
}

CommandInitializer.$inject = ['eventBus', 'commandStack']
File renamed without changes.
5 changes: 5 additions & 0 deletions src/cmd/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import CommandInitializer from './CommandInitializer'

export default {
__init__: [CommandInitializer]
}
14 changes: 7 additions & 7 deletions types/declares/diagram.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,19 +753,19 @@ declare module 'diagram-js/lib/command/CommandStack' {
declare module 'diagram-js/lib/command/CommandHandler' {
import { Base } from 'diagram-js/lib/model'

export default abstract class CommandHandler {
abstract execute<E extends Base>(context: Object): E[]
abstract revert<E extends Base>(context: Object): E[]
abstract canExecute(context: Object): boolean
abstract preExecute(context: Object): void
abstract postExecute(context: Object): void
export default class CommandHandler {
execute<E extends Base>(context: Object): E[]
revert<E extends Base>(context: Object): E[]
canExecute(context: Object): boolean
preExecute(context: Object): void
postExecute(context: Object): void
}
}
// CommandHandler 实现类 的一个验证和扩展程序
declare module 'diagram-js/lib/command/CommandInterceptor' {
import EventBus from 'diagram-js/lib/core/EventBus'

export default abstract class CommandInterceptor {
export default class CommandInterceptor {
protected constructor(eventBus: EventBus)
on(
events: Function | number | string | string[],
Expand Down

0 comments on commit 876a377

Please sign in to comment.