df947f28a250fe14152c2047b8392aab.json 8.58 KB
{"ast":null,"code":"/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Command interface\r\n */\nimport snippet from 'tui-code-snippet';\nimport errorMessage from '../factory/errorMessage';\nconst createMessage = errorMessage.create;\nconst errorTypes = errorMessage.types;\n/**\r\n * Command class\r\n * @class\r\n * @param {{name:function, execute: function, undo: function,\r\n *          executeCallback: function, undoCallback: function}} actions - Command actions\r\n * @param {Array} args - passing arguments on execute, undo\r\n * @ignore\r\n */\n\nclass Command {\n  constructor(actions, args) {\n    /**\r\n     * command name\r\n     * @type {string}\r\n     */\n    this.name = actions.name;\n    /**\r\n     * arguments\r\n     * @type {Array}\r\n     */\n\n    this.args = args;\n    /**\r\n     * Execute function\r\n     * @type {function}\r\n     */\n\n    this.execute = actions.execute;\n    /**\r\n     * Undo function\r\n     * @type {function}\r\n     */\n\n    this.undo = actions.undo;\n    /**\r\n     * executeCallback\r\n     * @type {function}\r\n     */\n\n    this.executeCallback = actions.executeCallback || null;\n    /**\r\n     * undoCallback\r\n     * @type {function}\r\n     */\n\n    this.undoCallback = actions.undoCallback || null;\n    /**\r\n     * data for undo\r\n     * @type {Object}\r\n     */\n\n    this.undoData = {};\n  }\n  /**\r\n   * Execute action\r\n   * @param {Object.<string, Component>} compMap - Components injection\r\n   * @abstract\r\n   */\n\n\n  execute() {\n    throw new Error(createMessage(errorTypes.UN_IMPLEMENTATION, 'execute'));\n  }\n  /**\r\n   * Undo action\r\n   * @param {Object.<string, Component>} compMap - Components injection\r\n   * @abstract\r\n   */\n\n\n  undo() {\n    throw new Error(createMessage(errorTypes.UN_IMPLEMENTATION, 'undo'));\n  }\n  /**\r\n   * command for redo if undoData exists\r\n   * @returns {boolean} isRedo\r\n   */\n\n\n  get isRedo() {\n    return Object.keys(this.undoData).length;\n  }\n  /**\r\n   * Set undoData action\r\n   * @param {Object} undoData - maked undo data\r\n   * @param {Object} cachedUndoDataForSilent - cached undo data\r\n   * @param {boolean} isSilent - is silent execution or not\r\n   * @returns {Object} cachedUndoDataForSilent\r\n   */\n\n\n  setUndoData(undoData, cachedUndoDataForSilent, isSilent) {\n    if (cachedUndoDataForSilent) {\n      undoData = cachedUndoDataForSilent;\n    }\n\n    if (!isSilent) {\n      snippet.extend(this.undoData, undoData);\n      cachedUndoDataForSilent = null;\n    } else if (!cachedUndoDataForSilent) {\n      cachedUndoDataForSilent = undoData;\n    }\n\n    return cachedUndoDataForSilent;\n  }\n  /**\r\n   * Attach execute callabck\r\n   * @param {function} callback - Callback after execution\r\n   * @returns {Command} this\r\n   */\n\n\n  setExecuteCallback(callback) {\n    this.executeCallback = callback;\n    return this;\n  }\n  /**\r\n   * Attach undo callback\r\n   * @param {function} callback - Callback after undo\r\n   * @returns {Command} this\r\n   */\n\n\n  setUndoCallback(callback) {\n    this.undoCallback = callback;\n    return this;\n  }\n\n}\n\nexport default Command;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/src/js/interface/command.js"],"names":["snippet","errorMessage","createMessage","create","errorTypes","types","Command","constructor","actions","args","name","execute","undo","executeCallback","undoCallback","undoData","Error","UN_IMPLEMENTATION","isRedo","Object","keys","length","setUndoData","cachedUndoDataForSilent","isSilent","extend","setExecuteCallback","callback","setUndoCallback"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,kBAApB;AACA,OAAOC,YAAP,MAAyB,yBAAzB;AAEA,MAAMC,aAAa,GAAGD,YAAY,CAACE,MAAnC;AACA,MAAMC,UAAU,GAAGH,YAAY,CAACI,KAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,OAAN,CAAc;AACZC,EAAAA,WAAW,CAACC,OAAD,EAAUC,IAAV,EAAgB;AACzB;AACJ;AACA;AACA;AACI,SAAKC,IAAL,GAAYF,OAAO,CAACE,IAApB;AAEA;AACJ;AACA;AACA;;AACI,SAAKD,IAAL,GAAYA,IAAZ;AAE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,kBAAkB,CAACC,QAAD,EAAW;AAC3B,SAAKd,eAAL,GAAuBc,QAAvB;AAEA,WAAO,IAAP;AACD;AAED;AACF;AACA;AACA;AACA;;;AACEC,EAAAA,eAAe,CAACD,QAAD,EAAW;AACxB,SAAKb,YAAL,GAAoBa,QAApB;AAEA,WAAO,IAAP;AACD;;AAjHW;;AAoHd,eAAerB,OAAf","sourcesContent":["/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Command interface\r\n */\r\nimport snippet from 'tui-code-snippet';\r\nimport errorMessage from '../factory/errorMessage';\r\n\r\nconst createMessage = errorMessage.create;\r\nconst errorTypes = errorMessage.types;\r\n\r\n/**\r\n * Command class\r\n * @class\r\n * @param {{name:function, execute: function, undo: function,\r\n *          executeCallback: function, undoCallback: function}} actions - Command actions\r\n * @param {Array} args - passing arguments on execute, undo\r\n * @ignore\r\n */\r\nclass Command {\r\n  constructor(actions, args) {\r\n    /**\r\n     * command name\r\n     * @type {string}\r\n     */\r\n    this.name = actions.name;\r\n\r\n    /**\r\n     * arguments\r\n     * @type {Array}\r\n     */\r\n    this.args = args;\r\n\r\n    /**\r\n     * Execute function\r\n     * @type {function}\r\n     */\r\n    this.execute = actions.execute;\r\n\r\n    /**\r\n     * Undo function\r\n     * @type {function}\r\n     */\r\n    this.undo = actions.undo;\r\n\r\n    /**\r\n     * executeCallback\r\n     * @type {function}\r\n     */\r\n    this.executeCallback = actions.executeCallback || null;\r\n\r\n    /**\r\n     * undoCallback\r\n     * @type {function}\r\n     */\r\n    this.undoCallback = actions.undoCallback || null;\r\n\r\n    /**\r\n     * data for undo\r\n     * @type {Object}\r\n     */\r\n    this.undoData = {};\r\n  }\r\n\r\n  /**\r\n   * Execute action\r\n   * @param {Object.<string, Component>} compMap - Components injection\r\n   * @abstract\r\n   */\r\n  execute() {\r\n    throw new Error(createMessage(errorTypes.UN_IMPLEMENTATION, 'execute'));\r\n  }\r\n\r\n  /**\r\n   * Undo action\r\n   * @param {Object.<string, Component>} compMap - Components injection\r\n   * @abstract\r\n   */\r\n  undo() {\r\n    throw new Error(createMessage(errorTypes.UN_IMPLEMENTATION, 'undo'));\r\n  }\r\n\r\n  /**\r\n   * command for redo if undoData exists\r\n   * @returns {boolean} isRedo\r\n   */\r\n  get isRedo() {\r\n    return Object.keys(this.undoData).length;\r\n  }\r\n\r\n  /**\r\n   * Set undoData action\r\n   * @param {Object} undoData - maked undo data\r\n   * @param {Object} cachedUndoDataForSilent - cached undo data\r\n   * @param {boolean} isSilent - is silent execution or not\r\n   * @returns {Object} cachedUndoDataForSilent\r\n   */\r\n  setUndoData(undoData, cachedUndoDataForSilent, isSilent) {\r\n    if (cachedUndoDataForSilent) {\r\n      undoData = cachedUndoDataForSilent;\r\n    }\r\n\r\n    if (!isSilent) {\r\n      snippet.extend(this.undoData, undoData);\r\n      cachedUndoDataForSilent = null;\r\n    } else if (!cachedUndoDataForSilent) {\r\n      cachedUndoDataForSilent = undoData;\r\n    }\r\n\r\n    return cachedUndoDataForSilent;\r\n  }\r\n\r\n  /**\r\n   * Attach execute callabck\r\n   * @param {function} callback - Callback after execution\r\n   * @returns {Command} this\r\n   */\r\n  setExecuteCallback(callback) {\r\n    this.executeCallback = callback;\r\n\r\n    return this;\r\n  }\r\n\r\n  /**\r\n   * Attach undo callback\r\n   * @param {function} callback - Callback after undo\r\n   * @returns {Command} this\r\n   */\r\n  setUndoCallback(callback) {\r\n    this.undoCallback = callback;\r\n\r\n    return this;\r\n  }\r\n}\r\n\r\nexport default Command;\r\n"]},"metadata":{},"sourceType":"module"}