A CommandOptions object containing the unique command ID
Decorator function that registers the command class
import { AnyCommand, Command } from '@limetech/lime-web-components';
@Command({ id: 'generate-report' })
class GenerateReportCommand implements AnyCommand {
public reportType: string;
// Dates travel as ISO strings. A Date instance does not survive
// serialization, and the platform may serialize a command.
public startDate: string;
public endDate: string;
}
const command = new GenerateReportCommand();
command.reportType = 'sales';
command.startDate = '2024-01-01';
command.endDate = '2024-03-31';
import {
Command,
LimeObjectCommand,
LimeObjectContext,
} from '@limetech/lime-web-components';
// The platform instantiates a command without arguments and then assigns the
// properties, so a command class declares no constructor.
@Command({ id: 'send-email' })
class SendEmailCommand implements LimeObjectCommand {
public context: LimeObjectContext;
public subject: string;
public body: string;
}
const command = new SendEmailCommand();
command.context = { limetype: 'person', id: 42 };
command.subject = 'Meeting Invitation';
command.body = 'Please join us for a meeting...';
import {
Command,
Expression,
LimeObjectBulkCommand,
LimeTypeContext,
} from '@limetech/lime-web-components';
@Command({ id: 'export-to-excel' })
class ExportToExcelCommand implements LimeObjectBulkCommand {
public context: LimeTypeContext;
public filter: Expression | null;
public includeRelations = false;
}
const command = new ExportToExcelCommand();
command.context = { limetype: 'deal', id: null };
command.filter = null;
import {
Command,
Expression,
LimeObjectBulkCommand,
LimeObjectCommand,
LimeObjectContext,
LimeTypeContext,
PlatformServiceName,
} from '@limetech/lime-web-components';
@Command({ id: 'generate-pdf-report' })
class GeneratePdfReportCommand {
public reportType: string;
public includeCharts: boolean;
}
@Command({ id: 'archive-deal' })
class ArchiveDealCommand implements LimeObjectCommand {
public context: LimeObjectContext;
public reason: string;
}
@Command({ id: 'bulk-update-status' })
class BulkUpdateStatusCommand implements LimeObjectBulkCommand {
public context: LimeTypeContext;
public filter: Expression | null;
public newStatus: string;
}
declare module '@limetech/lime-web-components' {
interface CommandRegistry {
'generate-pdf-report': GeneratePdfReportCommand;
'archive-deal': ArchiveDealCommand;
'bulk-update-status': BulkUpdateStatusCommand;
}
}
const commandBus = platform.get(PlatformServiceName.CommandBus);
const command = commandBus.createCommand({
id: 'generate-pdf-report',
params: { reportType: 'monthly', includeCharts: true },
});
await commandBus.handle(command);
Decorator to register a class as a command with a unique identifier.
The
@Commanddecorator marks a class as a command and assigns it a unique ID that can be used for command lookup, registration, and execution. This decorator is essential for the command pattern implementation and enables type-safe command creation through the CommandRegistry.