mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(util) exec.parallel: callback(args) -> callback(error, args)
This commit is contained in:
parent
90ebc3e653
commit
648ceea602
16 changed files with 101 additions and 72 deletions
|
|
@ -11,9 +11,9 @@
|
|||
if (opener) {
|
||||
var CloudCmd = opener.CloudCmd;
|
||||
|
||||
CloudCmd.getModules(function(pModules) {
|
||||
CloudCmd.getModules(function(error, modules) {
|
||||
var Util = opener.Util,
|
||||
Storage = Util.findObjByNameInArr(pModules, 'storage'),
|
||||
Storage = Util.findObjByNameInArr(modules, 'storage'),
|
||||
GitHub = Util.findObjByNameInArr(Storage, 'GitHub'),
|
||||
GitHub_ID = GitHub && GitHub.key;
|
||||
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ var Util, DOM, CloudFunc;
|
|||
});
|
||||
});
|
||||
|
||||
CloudCmd.getModules(function(modules) {
|
||||
CloudCmd.getModules(function(error, modules) {
|
||||
var storageObj, mod, path,
|
||||
STORAGE = 'storage',
|
||||
showLoad = Images.showLoad.bind(Images),
|
||||
|
|
@ -262,7 +262,7 @@ var Util, DOM, CloudFunc;
|
|||
|
||||
Listeners.initKeysPanel();
|
||||
|
||||
CloudCmd.getConfig(function(config) {
|
||||
CloudCmd.getConfig(function(error, config) {
|
||||
var localStorage = config.localStorage,
|
||||
dirPath = DOM.getCurrentDirPath();
|
||||
|
||||
|
|
@ -290,26 +290,32 @@ var Util, DOM, CloudFunc;
|
|||
func(callback);
|
||||
};
|
||||
|
||||
function getSystemFile(pGlobal, pURL) {
|
||||
|
||||
function lGetSysFile(callback) {
|
||||
Util.exec.if(pGlobal, callback, function() {
|
||||
function getSystemFile(global, url) {
|
||||
var get = function (callback) {
|
||||
var success = Util.exec.with(callback, null);
|
||||
|
||||
Util.exec.if(global, success, function() {
|
||||
DOM.load.ajax({
|
||||
url : pURL,
|
||||
success : function(pLocal) {
|
||||
pGlobal = pLocal;
|
||||
Util.exec(callback, pLocal);
|
||||
url : url,
|
||||
success : function(local) {
|
||||
global = local;
|
||||
success(local);
|
||||
},
|
||||
error : function(error) {
|
||||
callback(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return lGetSysFile;
|
||||
return get;
|
||||
}
|
||||
|
||||
this.setConfig = function(config) { Config = config; };
|
||||
this.getConfig = function(callback) {
|
||||
Util.exec.if(Config, callback, function() {
|
||||
var func = Util.exec.with(callback, null);
|
||||
|
||||
Util.exec.if(Config, func, function(callback) {
|
||||
var RESTful = DOM.RESTful;
|
||||
|
||||
RESTful.Config.read(function(config) {
|
||||
|
|
@ -409,7 +415,7 @@ var Util, DOM, CloudFunc;
|
|||
CloudCmd.getLinkTemplate
|
||||
];
|
||||
|
||||
Util.exec.parallel(funcs, function(templFile, templPath, templPathLink, templLink) {
|
||||
Util.exec.parallel(funcs, function(error, templFile, templPath, templPathLink, templLink) {
|
||||
var n, found, varCurrent, varName, current,
|
||||
dir = DOM.getCurrentDirName(),
|
||||
name = DOM.getCurrentName(),
|
||||
|
|
|
|||
|
|
@ -46,11 +46,11 @@ var CloudCmd, Util, DOM;
|
|||
}
|
||||
};
|
||||
|
||||
function fillTemplate(template) {
|
||||
function fillTemplate(error, template) {
|
||||
if (!Template)
|
||||
Template = template;
|
||||
|
||||
CloudCmd.getConfig(function(config) {
|
||||
CloudCmd.getConfig(function(error, config) {
|
||||
var div, data, inputs, inputFirst,
|
||||
focus, obj;
|
||||
|
||||
|
|
|
|||
|
|
@ -333,52 +333,68 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
return ret;
|
||||
}
|
||||
|
||||
function loadRemote(name, callback) {
|
||||
this.loadRemote = function(name, callback) {
|
||||
var getConfig = CloudCmd.getConfig,
|
||||
getModules = CloudCmd.getModules;
|
||||
|
||||
Util.exec.parallel([getConfig, getModules], function(config, modules) {
|
||||
var load = DOM.load,
|
||||
Util.exec.parallel([getConfig, getModules], function(error, config, modules) {
|
||||
var remoteTmpls, local, remote,
|
||||
load = DOM.load,
|
||||
online = config.online && navigator.onLine,
|
||||
|
||||
remoteObj = Util.findObjByNameInArr(modules, 'remote'),
|
||||
jquery = Util.findObjByNameInArr(remoteObj, name),
|
||||
module = Util.findObjByNameInArr(remoteObj, name),
|
||||
|
||||
version = jquery.version,
|
||||
local = jquery.local,
|
||||
remoteTmpl = jquery.remote,
|
||||
|
||||
remote = Util.render(remoteTmpl, {
|
||||
version: version
|
||||
}),
|
||||
version = module.version,
|
||||
isArray = Util.isArray(module.local),
|
||||
|
||||
funcON = function() {
|
||||
load.js(remote, {
|
||||
onload : callback,
|
||||
onerror : funcOFF
|
||||
load.parallel(remote, function(error) {
|
||||
if (error)
|
||||
funcOFF();
|
||||
else
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
funcOFF = function() {
|
||||
load.js(local, {
|
||||
onload : callback
|
||||
});
|
||||
load.parallel(local, callback);
|
||||
};
|
||||
|
||||
|
||||
if (isArray) {
|
||||
remoteTmpls = module.remote;
|
||||
local = module.local;
|
||||
} else {
|
||||
remoteTmpls = [module.remote];
|
||||
local = [module.local];
|
||||
}
|
||||
|
||||
remote = remoteTmpls.map(function(item) {
|
||||
return Util.render(item, {
|
||||
version: version
|
||||
});
|
||||
});
|
||||
|
||||
Util.exec.if(online, funcON, funcOFF);
|
||||
});
|
||||
}
|
||||
|
||||
return DOM;
|
||||
};
|
||||
|
||||
/**
|
||||
* load jquery from google cdn or local copy
|
||||
* @param callback
|
||||
*/
|
||||
this.loadJquery = function(callback) {
|
||||
loadRemote('jquery', callback);
|
||||
var ret = DOM.loadRemote('jquery', callback);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
this.loadSocket = function(callback) {
|
||||
loadRemote('socket', callback);
|
||||
var ret = DOM.loadRemote('socket', callback);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/** function loads css and js of Menu
|
||||
|
|
@ -1201,7 +1217,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
* @param callback
|
||||
*/
|
||||
this.saveDataToStorage = function(name, data, hash, callback) {
|
||||
CloudCmd.getConfig(function(config) {
|
||||
CloudCmd.getConfig(function(error, config) {
|
||||
var allowed = config.localStorage,
|
||||
isDir = DOM.isCurrentIsDir(),
|
||||
nameHash = name + '-hash',
|
||||
|
|
@ -1234,7 +1250,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
* @param callback
|
||||
*/
|
||||
this.getDataFromStorage = function(name, callback) {
|
||||
CloudCmd.getConfig(function(config) {
|
||||
CloudCmd.getConfig(function(error, config) {
|
||||
var Storage = DOM.Storage,
|
||||
nameHash = name + '-hash',
|
||||
nameData = name + '-data',
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
|
|||
var path = Info.path,
|
||||
value = Ace.getValue();
|
||||
|
||||
CloudCmd.getConfig(function(config) {
|
||||
CloudCmd.getConfig(function(error, config) {
|
||||
var isDiff = config.diff,
|
||||
isZip = config.zip;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ var Util, DOM, CloudCmd;
|
|||
};
|
||||
|
||||
this.analytics = function() {
|
||||
getConfig(function(config) {
|
||||
getConfig(function(error, config) {
|
||||
var analytics = config.analytics,
|
||||
online = config.online;
|
||||
|
||||
|
|
@ -241,7 +241,7 @@ var Util, DOM, CloudCmd;
|
|||
}
|
||||
|
||||
function appStorage() {
|
||||
getConfig(function(config) {
|
||||
getConfig(function(error, config) {
|
||||
var isAppStorage = config.appStorage,
|
||||
appStorage = window.applicationStorage;
|
||||
|
||||
|
|
|
|||
|
|
@ -43,13 +43,13 @@ var Util, DOM;
|
|||
*
|
||||
* if object - then onload and onerror
|
||||
*/
|
||||
funcLoad = function(event) {
|
||||
funcLoad = function() {
|
||||
Events.remove('error', element, funcError);
|
||||
|
||||
Util.exec(func, event);
|
||||
Util.exec(func);
|
||||
},
|
||||
|
||||
funcError = function() {
|
||||
funcError = function(event) {
|
||||
var template = 'file {{ src }} could not be loaded',
|
||||
isQuit = !!onError,
|
||||
msg = Util.render(template, {
|
||||
|
|
@ -60,12 +60,15 @@ var Util, DOM;
|
|||
|
||||
Images.showError(msg, isQuit);
|
||||
|
||||
Util.exec(onError);
|
||||
Util.exec(onError, event);
|
||||
};
|
||||
|
||||
if (isObj) {
|
||||
onError = func.onerror;
|
||||
func = func.onload;
|
||||
onError = func.onerror;
|
||||
|
||||
if (!onError)
|
||||
onError = func.onload;
|
||||
}
|
||||
/* убираем путь к файлу, оставляя только название файла */
|
||||
if (!p.id && p.src)
|
||||
|
|
@ -278,6 +281,7 @@ var Util, DOM;
|
|||
funcs = params.map(function(url) {
|
||||
return load.ext.bind(null, url);
|
||||
});
|
||||
|
||||
Util.exec.parallel(funcs, callback);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
|
|||
}
|
||||
|
||||
function getUploadTo(callback) {
|
||||
CloudCmd.getModules(function(modules) {
|
||||
CloudCmd.getModules(function(error, modules) {
|
||||
var menu = {},
|
||||
storage = Util.findObjByNameInArr(modules, 'storage'),
|
||||
items = Util.getNamesFromObjArray(storage) || [];
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ var Util, DOM, CloudCmd;
|
|||
});
|
||||
|
||||
this.send = function(msg) {
|
||||
CloudCmd.getConfig(function(config) {
|
||||
CloudCmd.getConfig(function(error, config) {
|
||||
var notify,
|
||||
notifications = config.notifications,
|
||||
focus = window.focus.bind(window),
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dropbox, cb, Client;
|
|||
* @param pData = {key, secret}
|
||||
*/
|
||||
this.login = function(callback) {
|
||||
CloudCmd.getModules(function(modules){
|
||||
CloudCmd.getModules(function(error, modules){
|
||||
var url = CloudCmd.HOST + '/html/auth/dropbox.html',
|
||||
storage = Util.findObjByNameInArr(modules, 'storage'),
|
||||
dropbox = Util.findObjByNameInArr(storage, 'DropBox'),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
var CloudCmd, DOM, Dropbox;
|
||||
var Util, CloudCmd, DOM, Dropbox;
|
||||
|
||||
(function(CloudCmd, DOM){
|
||||
(function(Util, CloudCmd, DOM){
|
||||
'use strict';
|
||||
|
||||
var CHOOSER_API = 'https://www.dropbox.com/static/api/1/dropbox.js',
|
||||
|
|
@ -21,10 +21,10 @@ var CloudCmd, DOM, Dropbox;
|
|||
* function loads dropbox.js
|
||||
*/
|
||||
function load(){
|
||||
console.time('dropbox load');
|
||||
Util.time('dropbox load');
|
||||
|
||||
CloudCmd.getConfig(function(pConfig){
|
||||
var lElement = DOM.load({
|
||||
CloudCmd.getConfig(function(error, config){
|
||||
var element = DOM.load({
|
||||
src : CHOOSER_API,
|
||||
notAppend : true,
|
||||
id : 'dropboxjs',
|
||||
|
|
@ -32,11 +32,11 @@ var CloudCmd, DOM, Dropbox;
|
|||
|
||||
});
|
||||
|
||||
var lDropBoxId = pConfig.dropbox_chooser_key;
|
||||
lElement.setAttribute('data-app-key', lDropBoxId);
|
||||
document.body.appendChild(lElement);
|
||||
var lDropBoxId = config.dropbox_chooser_key;
|
||||
element.setAttribute('data-app-key', lDropBoxId);
|
||||
document.body.appendChild(element);
|
||||
|
||||
console.timeEnd('dropbox load');
|
||||
Util.timeEnd('dropbox load');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -49,4 +49,4 @@ var CloudCmd, DOM, Dropbox;
|
|||
};
|
||||
|
||||
CloudCmd.DropBox = DropBoxStore;
|
||||
})(CloudCmd, DOM);
|
||||
})(Util, CloudCmd, DOM);
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ var CloudCmd, Util, DOM, filepicker;
|
|||
Util.time('filepicker load');
|
||||
|
||||
DOM.load.js('//api.filepicker.io/v1/filepicker.js', function() {
|
||||
CloudCmd.getModules(function(modules) {
|
||||
CloudCmd.getModules(function(error, modules) {
|
||||
var storage = Util.findObjByNameInArr(modules, 'storage'),
|
||||
picker = Util.findObjByNameInArr(storage, 'FilePicker'),
|
||||
key = picker && picker.key;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ var CloudCmd, Util, DOM, gapi;
|
|||
var lUrl = 'https://apis.google.com/js/client.js';
|
||||
|
||||
DOM.load.js(lUrl, function() {
|
||||
CloudCmd.getModules(function(modules) {
|
||||
CloudCmd.getModules(function(error, modules) {
|
||||
var storage = Util.findObjByNameInArr(modules, 'storage'),
|
||||
gDrive = Util.findObjByNameInArr(storage, 'GDrive'),
|
||||
gDriveId = gDrive && gDrive.id,
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ var CloudCmd, Util, DOM, WL;
|
|||
}
|
||||
|
||||
function auth() {
|
||||
CloudCmd.getModules(function(pModules){
|
||||
var lStorage = Util.findObjByNameInArr(pModules, 'storage'),
|
||||
CloudCmd.getModules(function(error, modules){
|
||||
var lStorage = Util.findObjByNameInArr(modules, 'storage'),
|
||||
lSkyDrive = Util.findObjByNameInArr(lStorage, 'SkyDrive'),
|
||||
lSkyDriveKey = lSkyDrive && lSkyDrive.id;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ var CloudCmd, Util, DOM, VK;
|
|||
|
||||
}
|
||||
|
||||
function auth(pCallBack){
|
||||
CloudCmd.getConfig(function(pConfig){
|
||||
function auth(callback) {
|
||||
CloudCmd.getConfig(function(error, config){
|
||||
var lDOCUMENTS_ACCESS = 131072;
|
||||
|
||||
VK.init({ apiId: pConfig.vk_id});
|
||||
VK.init({ apiId: config.vk_id});
|
||||
|
||||
VK.Auth.login(function(){
|
||||
var lNAME = 1281;
|
||||
|
|
@ -46,7 +46,7 @@ var CloudCmd, Util, DOM, VK;
|
|||
Util.log ('Hello, ' + lName + ':)');
|
||||
});
|
||||
|
||||
Util.exec(pCallBack);
|
||||
Util.exec(callback);
|
||||
|
||||
}, lDOCUMENTS_ACCESS); /* Доступ к документам пользователя */
|
||||
});
|
||||
|
|
|
|||
|
|
@ -39,9 +39,12 @@
|
|||
minifyName = Minify.getName(name),
|
||||
|
||||
isChanged = exec.with(IsChanged.isFileChanged, name),
|
||||
isExist = exec.with(fs.exists, minifyName);
|
||||
isExist = function(callback) {
|
||||
var func = exec.ret(callback, null);
|
||||
fs.exists(minifyName, func);
|
||||
};
|
||||
|
||||
exec.parallel([isChanged, isExist], function(changed, exists) {
|
||||
exec.parallel([isChanged, isExist], function(error, changed, exists) {
|
||||
if (changed || !exists)
|
||||
Minify.optimize(name, params);
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue