API Reference
@univerjs
@univerjs/core
classes
Commandservice

@univerjs/core v0.4.2Docs


Class: CommandService

The service to register and execute commands.

Extends

Implements

Constructors

new CommandService()

new CommandService(_injector, _logService): CommandService

Parameters

ParameterType
_injectorInjector
_logServiceILogService

Returns

CommandService

Overrides

Disposable.constructor

Defined in

submodules/univer/packages/core/src/services/command/command.service.ts:293 (opens in a new tab)

Properties

PropertyModifierTypeDefault valueInherited fromDefined in
_commandRegistryreadonlyCommandRegistryundefined-submodules/univer/packages/core/src/services/command/command.service.ts:282 (opens in a new tab)
_disposedprotectedbooleanfalseDisposable._disposedsubmodules/univer/packages/core/src/shared/lifecycle.ts:93 (opens in a new tab)

Methods

beforeCommandExecuted()

beforeCommandExecuted(listener): IDisposable

Register a callback function that will be executed before a command is executed.

Parameters

ParameterType
listenerCommandListener

Returns

IDisposable

Implementation of

ICommandService.beforeCommandExecuted

Defined in

submodules/univer/packages/core/src/services/command/command.service.ts:322 (opens in a new tab)


dispose()

dispose(): void

Returns

void

Overrides

Disposable.dispose

Defined in

submodules/univer/packages/core/src/services/command/command.service.ts:303 (opens in a new tab)


disposeWithMe()

disposeWithMe(disposable): IDisposable

Parameters

ParameterType
disposableDisposableLike

Returns

IDisposable

Inherited from

Disposable.disposeWithMe

Defined in

submodules/univer/packages/core/src/shared/lifecycle.ts:96 (opens in a new tab)


ensureNotDisposed()

protected ensureNotDisposed(): void

Returns

void

Inherited from

Disposable.ensureNotDisposed

Defined in

submodules/univer/packages/core/src/shared/lifecycle.ts:100 (opens in a new tab)


executeCommand()

executeCommand<P, R>(
   id, 
   params?, 
options?): Promise<R>

Execute a command with the given id and parameters.

Type Parameters

Type ParameterDefault type
P extends objectobject
Rboolean

Parameters

ParameterTypeDescription
idstringIdentifier of the command.
params?PParameters of this execution.
options?IExecutionOptionsOptions of this execution.

Returns

Promise<R>

The result of the execution. It is a boolean value by default which indicates the command is executed.

Implementation of

ICommandService.executeCommand

Defined in

submodules/univer/packages/core/src/services/command/command.service.ts:348 (opens in a new tab)


hasCommand()

hasCommand(commandId): boolean

Check if a command is already registered at the current command service.

Parameters

ParameterTypeDescription
commandIdstringThe id of the command.

Returns

boolean

If the command is registered, return true, otherwise return false.

Implementation of

ICommandService.hasCommand

Defined in

submodules/univer/packages/core/src/services/command/command.service.ts:310 (opens in a new tab)


onCommandExecuted()

onCommandExecuted(listener): IDisposable

Register a callback function that will be executed after a command is executed.

Parameters

ParameterType
listener(commandInfo) => void

Returns

IDisposable

Implementation of

ICommandService.onCommandExecuted

Defined in

submodules/univer/packages/core/src/services/command/command.service.ts:335 (opens in a new tab)


registerCommand()

registerCommand(command): IDisposable

Register a command to the command service.

Parameters

ParameterTypeDescription
commandICommand<object, boolean>The command to register.

Returns

IDisposable

Implementation of

ICommandService.registerCommand

Defined in

submodules/univer/packages/core/src/services/command/command.service.ts:314 (opens in a new tab)


registerMultipleCommand()

registerMultipleCommand(command): IDisposable

Register a command as a multi command.

Parameters

ParameterTypeDescription
commandICommand<object, boolean>The command to register as a multi command.

Returns

IDisposable

Implementation of

ICommandService.registerMultipleCommand

Defined in

submodules/univer/packages/core/src/services/command/command.service.ts:318 (opens in a new tab)


syncExecuteCommand()

syncExecuteCommand<P, R>(
   id, 
   params?, 
   options?): R

Execute a command with the given id and parameters synchronously.

Type Parameters

Type ParameterDefault type
P extends objectobject
Rboolean

Parameters

ParameterTypeDescription
idstringIdentifier of the command.
params?PParameters of this execution.
options?IExecutionOptionsOptions of this execution.

Returns

R

The result of the execution. It is a boolean value by default which indicates the command is executed.

Implementation of

ICommandService.syncExecuteCommand

Defined in

submodules/univer/packages/core/src/services/command/command.service.ts:387 (opens in a new tab)


Copyright © 2021-2024 DreamNum Co,Ltd. All Rights Reserved.