diff --git a/client/modules/edit-file.js b/client/modules/edit-file.js index eb39444a..0c0d18ef 100644 --- a/client/modules/edit-file.js +++ b/client/modules/edit-file.js @@ -3,6 +3,14 @@ /* global CloudCmd, DOM, MenuIO */ const Format = require('format-io'); +const currify = require('currify/legacy'); +const squad = require('squad'); +const store = require('../../common/store'); + +const call = currify((fn, callback) => { + fn(); + callback(); +}); CloudCmd.EditFile = function EditFileProto(callback) { const Info = DOM.CurrentInfo; @@ -25,26 +33,19 @@ CloudCmd.EditFile = function EditFileProto(callback) { }; function init(callback) { - let editor; + const editor = store(); + + const getMainEditor = () => CloudCmd.Edit.getEditor(); + const getEditor = squad(editor, getMainEditor); + const auth = squad(authCheck, editor); + const listeners = squad(setListeners, editor); exec.series([ CloudCmd.Edit, - (callback) => { - editor = CloudCmd.Edit.getEditor(); - callback(); - }, - (callback) => { - authCheck(editor); - callback(); - }, - - (callback) => { - setListeners(editor); - callback(); - }, - (callback) => { - EditFile.show(callback); - }, + call(getEditor), + call(auth), + call(listeners), + EditFile.show, ], callback); } diff --git a/client/modules/edit.js b/client/modules/edit.js index 860616be..e3c42cbf 100644 --- a/client/modules/edit.js +++ b/client/modules/edit.js @@ -64,16 +64,17 @@ function EditProto(callback) { function initConfig(options = {}) { const config = Object.assign({}, options, ConfigView); - if (options.afterShow) { - checkFn('options.afterShow', options.afterShow); - - const afterShow = {config}; - - config.afterShow = () => { - afterShow(); - options.afterShow(); - }; - } + if (!options.afterShow) + return config; + + checkFn('options.afterShow', options.afterShow); + + const afterShow = {config}; + + config.afterShow = () => { + afterShow(); + options.afterShow(); + }; return config; } diff --git a/common/store.js b/common/store.js new file mode 100644 index 00000000..7a94054f --- /dev/null +++ b/common/store.js @@ -0,0 +1,13 @@ +'use strict'; + +module.exports = () => { + const data = {}; + + return (value) => { + if (typeof value !== 'undefined') + data.value = value; + + return data.value; + }; +}; + diff --git a/server/cloudfunc.js b/server/cloudfunc.js index d905bfa1..b491a085 100644 --- a/server/cloudfunc.js +++ b/server/cloudfunc.js @@ -2,6 +2,7 @@ const rendy = require('rendy'); const Entity = require('./entity'); +const store = require('../common/store'); /* КОНСТАНТЫ (общие для клиента и сервера)*/ @@ -226,13 +227,3 @@ function getSize(size) { return size; } -function store() { - const data = {}; - return (value) => { - if (typeof value !== 'undefined') - data.value = value; - - return data.value; - }; -} - diff --git a/test/common/store.js b/test/common/store.js new file mode 100644 index 00000000..78a2db5c --- /dev/null +++ b/test/common/store.js @@ -0,0 +1,22 @@ +'use strict'; + +const dir = '../../common'; +const store = require(`${dir}/store`); +const test = require('tape'); + +test('cloudcmd: common: store: set', (t) => { + const name = store(); + const str = 'hello'; + name(str); + + t.equal(name(), str, 'should return stored value'); + t.end(); +}); + +test('cloudcmd: common: store: first get', (t) => { + const name = store(); + + t.equal(name(), undefined, 'should return undefined'); + t.end(); +}); +