From 44b9a2b4a28c658456fc3c67744d3cd1f172542c Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Wed, 25 Jul 2018 01:10:13 +0200 Subject: [PATCH] Add `run` and `stop` methods in Commands module --- src/commands/index.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/commands/index.js b/src/commands/index.js index d51cb80a6..e1d533441 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -17,6 +17,8 @@ * * [add](#add) * * [get](#get) * * [has](#has) + * * [run](#run) + * * [stop](#stop) * * @module Commands */ @@ -253,6 +255,40 @@ module.exports = () => { return !!commands[id]; }, + /** + * Execute the command + * @param {String} id Command ID + * @param {Object} [options={}] Options + * @return {*} The return is defined by the command + * @example + * commands.run('myCommand', { someOption: 1 }); + */ + run(id, options = {}) { + let result; + const command = this.get(id); + const editor = em.get('Editor'); + if (command) result = command.callRun(editor, options); + + return result; + }, + + /** + * Stop the command + * @param {String} id Command ID + * @param {Object} [options={}] Options + * @return {*} The return is defined by the command + * @example + * commands.stop('myCommand', { someOption: 1 }); + */ + stop(id, options = {}) { + let result; + const command = this.get(id); + const editor = em.get('Editor'); + if (command) result = command.callStop(editor, options); + + return result; + }, + /** * Load default commands * @return {this}