There are two ways of hooking into behaviors like element creation. You can hook into events and commands. Hooking into events that result from command execution and executing additional commands will leave these as separate commands on the command stack. Hooking into commands will allow you to execute additional commands that will not end up as separate commands. You can use a CommandInterceptor
for that purpose.
Here’s an example:
class DefaultElementName extends CommandInterceptor {
constructor(eventBus, modeling) {
super(eventBus);
this.postExecute("shape.create", ({ context }) => {
const { shape } = context;
const { id } = shape;
modeling.updateLabel(shape, id);
});
}
}