Skip to content

Commit

Permalink
feature(cloudcmd) add emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Mar 19, 2018
1 parent f1bb0bf commit a3271da
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
13 changes: 12 additions & 1 deletion client/client.js
@@ -1,6 +1,8 @@
'use strict';

const itype = require('itype/legacy');
const emitify = require('emitify/legacy');
const inherits = require('inherits');
const rendy = require('rendy');
const exec = require('execon');
const Images = require('./dom/images');
Expand All @@ -15,6 +17,8 @@ const {

/* global Util, DOM */

inherits(CloudCmdProto, Emitify);

module.exports = new CloudCmdProto(Util, DOM);

function CloudCmdProto(Util, DOM) {
Expand All @@ -29,6 +33,8 @@ function CloudCmdProto(Util, DOM) {
console.log(str);
};

Emitify.call(this);

const CloudCmd = this;
const Info = DOM.CurrentInfo;
const Storage = DOM.Storage;
Expand Down Expand Up @@ -254,6 +260,7 @@ function CloudCmdProto(Util, DOM) {
}

DOM.setCurrentFile(current);

CloudCmd.execFromModule(module, 'show');
};

Expand Down Expand Up @@ -313,6 +320,8 @@ function CloudCmdProto(Util, DOM) {
function baseInit(callback) {
const files = DOM.getFiles();

CloudCmd.on('current-file', DOM.updateCurrentInfo);

/* выделяем строку с первым файлом */
if (files)
DOM.setCurrentFile(files[0], {
Expand Down Expand Up @@ -510,10 +519,12 @@ function CloudCmdProto(Util, DOM) {

if (!current)
current = DOM.getFiles(panel)[0];

DOM.setCurrentFile(current, {
history: history
});

CloudCmd.emit('active-dir', Info.dirPath);
}

exec(callback);
Expand Down
21 changes: 13 additions & 8 deletions client/dom/index.js
Expand Up @@ -159,7 +159,7 @@ function CmdProto() {
* get current direcotory path
*/
this.getCurrentDirPath = (panel = DOM.getPanel()) => {
const path = DOM.getByDataName('js-path', panel);
const path = DOM.getByDataName('js-path', panel);
const ret = path && path.textContent;

return ret;
Expand Down Expand Up @@ -473,17 +473,17 @@ function CmdProto() {
* to prevent default behavior
*/
if (!o || o.history !== false) {
if (path !== '/')
path = FS + path;

DOM.setHistory(path, null, path);
const historyPath = path === '/' ? path : FS + path;
DOM.setHistory(historyPath, null, historyPath);
}
}

/* scrolling to current file */
DOM.scrollIntoViewIfNeeded(currentFile, CENTER);

Cmd.updateCurrentInfo(currentFile);
CloudCmd.emit('current-file', currentFile);
CloudCmd.emit('current-path', path);
CloudCmd.emit('current-name', DOM.getCurrentName(currentFile));

return DOM;
};
Expand Down Expand Up @@ -1031,7 +1031,6 @@ function CmdProto() {
return;

DOM.setCurrentName(to, current);
Cmd.updateCurrentInfo(current);
Storage.remove(dirPath);

if (isExist)
Expand Down Expand Up @@ -1062,7 +1061,7 @@ function CmdProto() {
};

/* scroll on one page*/
this.scrollByPages = (element, pPages) => {
this.scrollByPages = (element, pPages) => {
var ret = element && element.scrollByPages && pPages;

if (ret)
Expand All @@ -1072,7 +1071,11 @@ function CmdProto() {
};

this.changePanel = () => {
const Info = CurrentInfo;
let panel = DOM.getPanel();

CloudCmd.emit('passive-dir', Info.dirPath);

const panelPassive = DOM.getPanel({
active: false
});
Expand Down Expand Up @@ -1110,6 +1113,8 @@ function CmdProto() {
history: true
});

CloudCmd.emit('active-dir', Info.dirPath);

return DOM;
};

Expand Down
10 changes: 8 additions & 2 deletions client/modules/konsole.js
Expand Up @@ -6,8 +6,12 @@
/* global Console */

const exec = require('execon');
const currify = require('currify/legacy');
const Images = require('../dom/images');
const {Dialog} = DOM;
const {
Dialog,
CurrentInfo:Info,
} = DOM;

CloudCmd.Konsole = ConsoleProto;

Expand Down Expand Up @@ -63,20 +67,22 @@ function ConsoleProto() {
PASSIVE_DIR: DOM.getNotCurrentDirPath.bind(DOM),
CURRENT_NAME: DOM.getCurrentName.bind(DOM),
CURRENT_PATH: () => {
return DOM.CurrentInfo.path;
return Info.path;
}
};
}

function create(callback) {
const options = {
cwd: Info.dirPath,
env: getEnv(),
prefix: getPrefix(),
socketPath: CloudCmd.PREFIX,
};

Console(Element, options, (spawn) => {
spawn.on('connect', exec.with(authCheck, spawn));

exec(callback);
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -171,6 +171,7 @@
"html-looks-like": "^1.0.2",
"html-webpack-exclude-assets-plugin": "^0.0.5",
"html-webpack-plugin": "^2.29.0",
"inherits": "^2.0.3",
"jscs": "^3.0.1",
"jshint": "^2.8.0",
"minor": "^1.2.2",
Expand Down

0 comments on commit a3271da

Please sign in to comment.