mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(util) bind -> exec.with
This commit is contained in:
parent
ec9a78a27a
commit
6b58016616
16 changed files with 61 additions and 60 deletions
|
|
@ -55,8 +55,8 @@
|
|||
name = 'ChangeLog';
|
||||
|
||||
Util.execParallel([
|
||||
Util.bind(exec, 'shell/log.sh ' + version),
|
||||
Util.bind(fs.readFile, name),
|
||||
Util.exec.with(exec, 'shell/log.sh ' + version),
|
||||
Util.exec.with(fs.readFile, name),
|
||||
], function(execParams, readParams) {
|
||||
var ERROR = 0,
|
||||
DATA = 1,
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ var Util, DOM, CloudFunc;
|
|||
Util.exec.series([
|
||||
initModules,
|
||||
baseInit,
|
||||
Util.bind(CloudCmd.route, location.hash)
|
||||
Util.exec.with(CloudCmd.route, location.hash)
|
||||
]);
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ var CloudCmd, Util, DOM;
|
|||
|
||||
this.show = function() {
|
||||
var funcs = [
|
||||
Util.bind(CloudCmd.getTemplate, Template, 'config'),
|
||||
Util.exec.with(CloudCmd.getTemplate, Template, 'config'),
|
||||
cssLoad
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
Loading,
|
||||
jqconsole,
|
||||
|
||||
log = Util.bind(write, 'log'),
|
||||
error = Util.bind(write, 'error'),
|
||||
log = Util.exec.with(write, 'log'),
|
||||
error = Util.exec.with(write, 'error'),
|
||||
|
||||
Element,
|
||||
MouseBinded,
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
|
|||
not_append : true
|
||||
});
|
||||
|
||||
onMenu = Util.bind(setMenu, Element);
|
||||
onMenu = Util.exec.with(setMenu, Element);
|
||||
|
||||
initAce();
|
||||
|
||||
|
|
@ -272,7 +272,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
|
|||
});
|
||||
});
|
||||
|
||||
}, Util.bind(doDiff, path));
|
||||
}, Util.exec.with(doDiff, path));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ var Util, DOM, CloudCmd;
|
|||
getConfig = CloudCmd.getConfig,
|
||||
OnPathLinks = [],
|
||||
EventsFiles = {
|
||||
'mousedown' : Util.bind(execIfNotUL, setCurrentFileByEvent),
|
||||
'mousedown' : Util.exec.with(execIfNotUL, setCurrentFileByEvent),
|
||||
'contextmenu' : onContextMenu,
|
||||
'dragstart' : Util.bind(execIfNotUL, onDragStart),
|
||||
'dragstart' : Util.exec.with(execIfNotUL, onDragStart),
|
||||
'click' : onClick,
|
||||
'dblclick' : Util.bind(execIfNotUL, onDblClick),
|
||||
'touchstart' : Util.bind(execIfNotUL, onTouch)
|
||||
'dblclick' : Util.exec.with(execIfNotUL, onDblClick),
|
||||
'touchstart' : Util.exec.with(execIfNotUL, onTouch)
|
||||
};
|
||||
|
||||
this.analytics = function() {
|
||||
|
|
@ -101,7 +101,7 @@ var Util, DOM, CloudCmd;
|
|||
for (i = 0; i < n; i++) {
|
||||
ai = pathLinks[i];
|
||||
link = Util.rmStr(ai.href, url),
|
||||
load = Util.bind(loadDir, {
|
||||
load = Util.exec.with(loadDir, {
|
||||
path : link,
|
||||
isRefresh : false,
|
||||
panel : panel
|
||||
|
|
@ -359,7 +359,7 @@ var Util, DOM, CloudCmd;
|
|||
|
||||
if (files.length) {
|
||||
Util.forEach(files, function(file) {
|
||||
func = Util.bind(load, file, func);
|
||||
func = Util.exec.with(load, file, func);
|
||||
});
|
||||
|
||||
func();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ var CloudCmd, Util, DOM;
|
|||
|
||||
Util.exec.series([
|
||||
CloudCmd.View,
|
||||
Util.bind(MD.show, null, null),
|
||||
Util.exec.with(MD.show, null, null),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
|
|||
options = {
|
||||
icon : true,
|
||||
beforeClose : Key.setBind,
|
||||
beforeShow : Util.bind(beforeShow, func),
|
||||
beforeShow : Util.exec.with(beforeShow, func),
|
||||
beforeClick : beforeClick,
|
||||
name : name
|
||||
};
|
||||
|
|
@ -114,8 +114,8 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
|
|||
},
|
||||
menuData = getMenuData(),
|
||||
menu = {
|
||||
'View' : Util.bind(show, 'View'),
|
||||
'Edit' : Util.bind(show, 'Edit'),
|
||||
'View' : Util.exec.with(show, 'View'),
|
||||
'Edit' : Util.exec.with(show, 'Edit'),
|
||||
'Rename' : function() {
|
||||
setTimeout(DOM.renameCurrent, 100);
|
||||
},
|
||||
|
|
@ -169,7 +169,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
|
|||
items = Util.getNamesFromObjArray(storage) || [];
|
||||
|
||||
items.forEach(function(name) {
|
||||
menu[name] = Util.bind(uploadTo, name);
|
||||
menu[name] = Util.exec.with(uploadTo, name);
|
||||
});
|
||||
|
||||
callback(menu);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
View.hide = hide;
|
||||
|
||||
function init() {
|
||||
var func = CallBack || Util.bind(show, null);
|
||||
var func = CallBack || Util.exec.with(show, null);
|
||||
|
||||
Loading = true;
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
className : 'view-overlay fancybox-overlay fancybox-overlay-fixed'
|
||||
});
|
||||
|
||||
Events.addClick(Util.bind(onOverLayClick, Overlay), Overlay);
|
||||
Events.addClick(Util.exec.with(onOverLayClick, Overlay), Overlay);
|
||||
Events.addKey(listener);
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +92,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
|
||||
if (isFunc) {
|
||||
func = config[name];
|
||||
config[name] = Util.bind(execParallel, [item, func]);
|
||||
config[name] = Util.exec.with(execParallel, [item, func]);
|
||||
} else {
|
||||
config[name] = options[name];
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
case 'media':
|
||||
getMediaElement(path, function(element) {
|
||||
var media = DOM.getByDataName('js-media', element),
|
||||
onKey = Util.bind(onMediaKey, media);
|
||||
onKey = Util.exec.with(onMediaKey, media);
|
||||
|
||||
$.fancybox.open(element, {
|
||||
parent : Overlay,
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
Rest, Route;
|
||||
|
||||
join = join && Util.bind(join, beforeJoin) || emptyHandler;
|
||||
join = join && Util.exec.with(join, beforeJoin) || emptyHandler;
|
||||
|
||||
/* базовая инициализация */
|
||||
function init(pAppCachProcessing) {
|
||||
|
|
@ -176,7 +176,7 @@
|
|||
]);
|
||||
|
||||
funcs.map(function(func) {
|
||||
return Util.bind(func, req, res);
|
||||
return Util.exec.with(func, req, res);
|
||||
});
|
||||
|
||||
Util.exec.series(funcs);
|
||||
|
|
@ -255,7 +255,7 @@
|
|||
names[i] = minName;
|
||||
}
|
||||
|
||||
funcs.push(Util.bind(minify, name));
|
||||
funcs.push(Util.exec.with(minify, name));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@
|
|||
|
||||
Clients[ConNum] = true;
|
||||
|
||||
onMessage = Util.bind(getOnMessage, ConNum, callback);
|
||||
onMessage = Util.exec.with(getOnMessage, ConNum, callback);
|
||||
onDisconnect = function(conNum) {
|
||||
Clients[conNum] =
|
||||
ClientFuncs[conNum] = null;
|
||||
|
|
@ -152,7 +152,7 @@
|
|||
}
|
||||
|
||||
if (!ClientFuncs[connNum])
|
||||
ClientFuncs[connNum] = Util.bind(setExec, function(json, error, stderr) {
|
||||
ClientFuncs[connNum] = Util.exec.with(setExec, function(json, error, stderr) {
|
||||
log(connNum, error, 'error');
|
||||
log(connNum, stderr, 'stderror');
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
fileCounter = 1;
|
||||
|
||||
function getDirInfo(dir) {
|
||||
stat(dir, Util.bind(getStat, dir));
|
||||
stat(dir, Util.exec.with(getStat, dir));
|
||||
}
|
||||
|
||||
function getStat(dir, error, stat) {
|
||||
|
|
|
|||
|
|
@ -11,16 +11,17 @@
|
|||
|
||||
function join(before, req, res, callback) {
|
||||
var names,
|
||||
readFunc = Util.bind(readPipe, req, res),
|
||||
exec = Util.exec,
|
||||
readFunc = exec.with(readPipe, req, res),
|
||||
path = main.getPathName(req),
|
||||
isJoin = CloudFunc.isJoinURL(path);
|
||||
|
||||
if (!isJoin)
|
||||
Util.exec(callback);
|
||||
else {
|
||||
if (!isJoin) {
|
||||
exec(callback);
|
||||
} else {
|
||||
names = CloudFunc.getJoinArray(path);
|
||||
|
||||
Util.exec.if(!before, readFunc, function(callback) {
|
||||
exec.if(!before, readFunc, function(callback) {
|
||||
before(names, callback);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,25 +29,26 @@
|
|||
INDEX : HTMLDIR + 'index.html',
|
||||
|
||||
optimize: function(name, params) {
|
||||
var minifyName, isChanged, isExist;
|
||||
var minifyName, isChanged, isExist,
|
||||
exec = Util.exec;
|
||||
|
||||
if (!Minify) {
|
||||
Util.log(COULD_NOT_MINIFY);
|
||||
Util.exec(params.callback);
|
||||
exec(params.callback);
|
||||
} else {
|
||||
minifyName = Minify.getName(name),
|
||||
|
||||
isChanged = Util.bind(IsChanged.isFileChanged, name),
|
||||
isExist = Util.bind(fs.exists, minifyName);
|
||||
isChanged = exec.with(IsChanged.isFileChanged, name),
|
||||
isExist = exec.with(fs.exists, minifyName);
|
||||
|
||||
if (!this.MinFolder)
|
||||
this.MinFolder = Minify.MinFolder;
|
||||
|
||||
Util.exec.parallel([isChanged, isExist], function(changed, exists) {
|
||||
exec.parallel([isChanged, isExist], function(changed, exists) {
|
||||
if (changed || !exists)
|
||||
Minify.optimize(name, params);
|
||||
else
|
||||
Util.exec(params.callback, null, {
|
||||
exec(params.callback, null, {
|
||||
name: minifyName
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -21,14 +21,14 @@
|
|||
WIN32 : 866
|
||||
},
|
||||
|
||||
exec = main.child_process.exec,
|
||||
processExec = main.child_process.exec,
|
||||
Util = main.util;
|
||||
|
||||
exports.getVolumes = function(callback) {
|
||||
var chcp = 'chcp ' + Charset.UNICODE,
|
||||
getVolumes = 'wmic logicaldisk get name';
|
||||
|
||||
exec(chcp + ' && ' + getVolumes, Util.bind(processOuput, callback));
|
||||
processExec(chcp + ' && ' + getVolumes, Util.exec.with(processOuput, callback));
|
||||
};
|
||||
|
||||
function processOuput(callback, error, stdout, stderr) {
|
||||
|
|
@ -42,7 +42,7 @@
|
|||
if (!error)
|
||||
error = stderr;
|
||||
|
||||
exec('chcp ' + Charset.WIN32);
|
||||
processExec('chcp ' + Charset.WIN32);
|
||||
|
||||
if(!error) {
|
||||
volumes = Util.rmStr(stdout, removeStr)
|
||||
|
|
|
|||
33
lib/util.js
33
lib/util.js
|
|
@ -11,21 +11,6 @@
|
|||
function UtilProto() {
|
||||
var Util = this;
|
||||
|
||||
/*
|
||||
* bind function to arguments without context
|
||||
*/
|
||||
|
||||
this.bind = function(callback) {
|
||||
var result,
|
||||
args = Util.slice(arguments, 1),
|
||||
bind = Function.prototype.bind;
|
||||
|
||||
args.unshift(null);
|
||||
result = bind.apply(callback, args);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/*
|
||||
* apply arguemnts to constructor
|
||||
*
|
||||
|
|
@ -690,16 +675,30 @@
|
|||
return ret;
|
||||
};
|
||||
|
||||
/*
|
||||
* return function that calls callback with arguments
|
||||
*/
|
||||
|
||||
exec.with = function(callback) {
|
||||
var result,
|
||||
bind = Function.prototype.bind;
|
||||
|
||||
arguments[0] = null;
|
||||
result = bind.apply(callback, arguments);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* return save exec function
|
||||
* @param callback
|
||||
*/
|
||||
exec.ret = function() {
|
||||
var result,
|
||||
args = Util.slice(arguments);
|
||||
args = Util.slice(arguments)
|
||||
|
||||
args.unshift(exec);
|
||||
result = Util.bind.apply(null, args);
|
||||
result = exec.with.apply(null, args);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue