Skip to content

Commit

Permalink
* core: support for execute command from HElement with only command …
Browse files Browse the repository at this point in the history
…name.
  • Loading branch information
catouse committed Oct 10, 2024
1 parent 5a3386e commit 385d90f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/core/src/react/components/h-element.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {h, Component} from 'preact';
import {deepCall} from '@zui/helpers';
import {nextGid} from '../../helpers/gid';
import {classes} from '../../helpers/classes';
import {getReactComponent} from './components';
Expand All @@ -9,7 +10,6 @@ import type {JSX, ComponentType, RenderableProps, ComponentChildren} from 'preac
import type {ClassNameLike} from '../../helpers/classes';
import type {HElementProps} from '../types';
import type {I18nLangMap} from '../../i18n';
import {deepCall} from '@zui/helpers/src/object';

/**
* The base HTML element.
Expand Down Expand Up @@ -133,10 +133,13 @@ export class HElement<P extends HElementProps, S = {}> extends Component<P, S> {
});
}

executeCommand(context: CommandContext, params: unknown[]) {
executeCommand(context: CommandContext | string, params: unknown[]) {
const {onCommand} = this.props;
let result;
if (context.scope === this.commandScope) {
if (typeof context === 'string') {
context = {name: context};
}
if (!context.scope || context.scope === this.commandScope) {
result = deepCall(this, context.name, params);
}
if (onCommand) {
Expand Down Expand Up @@ -183,7 +186,7 @@ export class HElement<P extends HElementProps, S = {}> extends Component<P, S> {

componentDidMount(): void {
const {commands, onCommand} = this.props;
if (commands && onCommand) {
if (commands || onCommand) {
bindCommands(this.element, {
commands,
scope: this.commandScope,
Expand Down

0 comments on commit 385d90f

Please sign in to comment.