Skip to content

Commit b85e3bb

Browse files
authored
Merge pull request nubasedev#65 from GraphCMS/master
Allow execute to return Promise<Value> or Value
2 parents 93ddbe4 + 7dd3079 commit b85e3bb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/ReactMde.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export class ReactMde extends React.Component<ReactMdeProps> {
3737
handleCommand = (command: Command) => {
3838
const {value: {text}, onChange} = this.props;
3939
const newValue = command.execute(text, getSelection(this.textArea));
40-
onChange(newValue);
40+
if (newValue instanceof Promise) {
41+
newValue.then((v) => onChange(v));
42+
} else {
43+
onChange(newValue);
44+
}
4145
}
4246

4347
/**

src/types/Command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export interface Command {
55
type?: string;
66
icon?: string;
77
tooltip?: string;
8-
execute: (text: string, selection: TextSelection) => Value;
8+
execute: (text: string, selection: TextSelection) => Value | Promise<Value>;
99
}

0 commit comments

Comments
 (0)