Browse Source

Add `run` and `stop` methods in Commands module

pull/1359/head
Artur Arseniev 8 years ago
parent
commit
44b9a2b4a2
  1. 36
      src/commands/index.js

36
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}

Loading…
Cancel
Save