separate console
This commit is contained in:
parent
22db12f2a3
commit
541449b1fc
13 changed files with 38 additions and 40 deletions
|
@ -1,12 +1,4 @@
|
|||
export default {
|
||||
// console commands
|
||||
CONSOLE_SHOW_COMMAND: 'console.show.command',
|
||||
CONSOLE_SET_COMPLETIONS: 'console.set.completions',
|
||||
CONSOLE_SHOW_ERROR: 'console.show.error',
|
||||
CONSOLE_HIDE: 'console.hide',
|
||||
CONSOLE_COMPLETION_NEXT: 'console.completion.next',
|
||||
CONSOLE_COMPLETION_PREV: 'console.completion.prev',
|
||||
|
||||
// User input
|
||||
INPUT_KEY_PRESS: 'input.key,press',
|
||||
INPUT_CLEAR_KEYS: 'input.clear.keys',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import actions from 'actions';
|
||||
import actions from 'console/actions';
|
||||
|
||||
const showCommand = (text) => {
|
||||
return {
|
9
src/console/actions/index.js
Normal file
9
src/console/actions/index.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
export default {
|
||||
// console commands
|
||||
CONSOLE_SHOW_COMMAND: 'console.show.command',
|
||||
CONSOLE_SET_COMPLETIONS: 'console.set.completions',
|
||||
CONSOLE_SHOW_ERROR: 'console.show.error',
|
||||
CONSOLE_HIDE: 'console.hide',
|
||||
CONSOLE_COMPLETION_NEXT: 'console.completion.next',
|
||||
CONSOLE_COMPLETION_PREV: 'console.completion.prev',
|
||||
};
|
|
@ -6,7 +6,7 @@ export default class Completion {
|
|||
}
|
||||
|
||||
update() {
|
||||
let state = this.store.getState().console;
|
||||
let state = this.store.getState();
|
||||
if (JSON.stringify(this.prevState) === JSON.stringify(state)) {
|
||||
return;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import messages from 'shared/messages';
|
||||
import * as consoleActions from 'actions/console';
|
||||
import * as consoleActions from 'console/actions/console';
|
||||
|
||||
export default class ConsoleComponent {
|
||||
constructor(wrapper, store) {
|
||||
|
@ -71,7 +71,7 @@ export default class ConsoleComponent {
|
|||
}
|
||||
|
||||
update() {
|
||||
let state = this.store.getState().console;
|
||||
let state = this.store.getState();
|
||||
if (!this.prevState.commandShown && state.commandShown) {
|
||||
this.showCommand(state.commandText);
|
||||
} else if (!state.commandShown) {
|
|
@ -1,10 +1,10 @@
|
|||
import './console.scss';
|
||||
import './site.scss';
|
||||
import messages from 'shared/messages';
|
||||
import CompletionComponent from 'components/completion';
|
||||
import ConsoleComponent from 'components/console';
|
||||
import reducers from 'reducers';
|
||||
import CompletionComponent from 'console/components/completion';
|
||||
import ConsoleComponent from 'console/components/console';
|
||||
import reducers from 'console/reducers';
|
||||
import { createStore } from 'store';
|
||||
import * as consoleActions from 'actions/console';
|
||||
import * as consoleActions from 'console/actions/console';
|
||||
|
||||
const store = createStore(reducers);
|
||||
let completionComponent = null;
|
|
@ -1,4 +1,4 @@
|
|||
import actions from 'actions';
|
||||
import actions from 'console/actions';
|
||||
|
||||
const defaultState = {
|
||||
errorShown: false,
|
|
@ -1,11 +1,9 @@
|
|||
import inputReducer from 'reducers/input';
|
||||
import consoleReducer from 'reducers/console';
|
||||
import settingReducer from 'reducers/setting';
|
||||
import followReducer from 'reducers/follow';
|
||||
|
||||
const defaultState = {
|
||||
input: inputReducer(undefined, {}),
|
||||
console: consoleReducer(undefined, {}),
|
||||
setting: settingReducer(undefined, {}),
|
||||
follow: followReducer(undefined, {}),
|
||||
};
|
||||
|
@ -13,7 +11,6 @@ const defaultState = {
|
|||
export default function reducer(state = defaultState, action = {}) {
|
||||
return Object.assign({}, state, {
|
||||
input: inputReducer(state.input, action),
|
||||
console: consoleReducer(state.console, action),
|
||||
setting: settingReducer(state.setting, action),
|
||||
follow: followReducer(state.follow, action),
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { expect } from "chai";
|
||||
import actions from 'actions';
|
||||
import * as consoleActions from 'actions/console';
|
||||
import actions from 'console/actions';
|
||||
import * as consoleActions from 'console/actions/console';
|
||||
|
||||
describe("console actions", () => {
|
||||
describe("showCommand", () => {
|
|
@ -1,10 +1,10 @@
|
|||
import { expect } from "chai";
|
||||
import actions from 'actions';
|
||||
import consoleReducer from 'reducers/console';
|
||||
import actions from 'console/actions';
|
||||
import reducer from 'console/reducers';
|
||||
|
||||
describe("console reducer", () => {
|
||||
it('return the initial state', () => {
|
||||
let state = consoleReducer(undefined, {});
|
||||
let state = reducer(undefined, {});
|
||||
expect(state).to.have.property('errorShown', false);
|
||||
expect(state).to.have.property('errorText', '');
|
||||
expect(state).to.have.property('commandShown', false);
|
||||
|
@ -16,7 +16,7 @@ describe("console reducer", () => {
|
|||
|
||||
it('return next state for CONSOLE_SHOW_COMMAND', () => {
|
||||
let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' };
|
||||
let state = consoleReducer({}, action);
|
||||
let state = reducer({}, action);
|
||||
expect(state).to.have.property('commandShown', true);
|
||||
expect(state).to.have.property('commandText', 'open ');
|
||||
expect(state).to.have.property('errorShown', false);
|
||||
|
@ -24,7 +24,7 @@ describe("console reducer", () => {
|
|||
|
||||
it('return next state for CONSOLE_SHOW_ERROR', () => {
|
||||
let action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' };
|
||||
let state = consoleReducer({}, action);
|
||||
let state = reducer({}, action);
|
||||
expect(state).to.have.property('errorShown', true);
|
||||
expect(state).to.have.property('errorText', 'an error');
|
||||
expect(state).to.have.property('commandShown', false);
|
||||
|
@ -32,7 +32,7 @@ describe("console reducer", () => {
|
|||
|
||||
it('return next state for CONSOLE_HIDE', () => {
|
||||
let action = { type: actions.CONSOLE_HIDE };
|
||||
let state = consoleReducer({}, action);
|
||||
let state = reducer({}, action);
|
||||
expect(state).to.have.property('errorShown', false);
|
||||
expect(state).to.have.property('commandShown', false);
|
||||
});
|
||||
|
@ -53,7 +53,7 @@ describe("console reducer", () => {
|
|||
items: [4, 5, 6]
|
||||
}]
|
||||
}
|
||||
state = consoleReducer(state, action);
|
||||
state = reducer(state, action);
|
||||
expect(state).to.have.property('completions', action.completions);
|
||||
expect(state).to.have.property('groupSelection', -1);
|
||||
expect(state).to.have.property('itemSelection', -1);
|
||||
|
@ -73,16 +73,16 @@ describe("console reducer", () => {
|
|||
}]
|
||||
};
|
||||
|
||||
state = consoleReducer(state, action);
|
||||
state = reducer(state, action);
|
||||
expect(state).to.have.property('groupSelection', 0);
|
||||
expect(state).to.have.property('itemSelection', 0);
|
||||
|
||||
state = consoleReducer(state, action);
|
||||
state = reducer(state, action);
|
||||
expect(state).to.have.property('groupSelection', 0);
|
||||
expect(state).to.have.property('itemSelection', 1);
|
||||
|
||||
state = consoleReducer(state, action);
|
||||
state = consoleReducer(state, action);
|
||||
state = reducer(state, action);
|
||||
state = reducer(state, action);
|
||||
expect(state).to.have.property('groupSelection', -1);
|
||||
expect(state).to.have.property('itemSelection', -1);
|
||||
});
|
||||
|
@ -101,16 +101,16 @@ describe("console reducer", () => {
|
|||
}]
|
||||
};
|
||||
|
||||
state = consoleReducer(state, action);
|
||||
state = reducer(state, action);
|
||||
expect(state).to.have.property('groupSelection', 1);
|
||||
expect(state).to.have.property('itemSelection', 0);
|
||||
|
||||
state = consoleReducer(state, action);
|
||||
state = reducer(state, action);
|
||||
expect(state).to.have.property('groupSelection', 0);
|
||||
expect(state).to.have.property('itemSelection', 1);
|
||||
|
||||
state = consoleReducer(state, action);
|
||||
state = consoleReducer(state, action);
|
||||
state = reducer(state, action);
|
||||
state = reducer(state, action);
|
||||
expect(state).to.have.property('groupSelection', -1);
|
||||
expect(state).to.have.property('itemSelection', -1);
|
||||
});
|
|
@ -9,7 +9,7 @@ module.exports = {
|
|||
index: path.join(src, 'content'),
|
||||
settings: path.join(src, 'pages/settings'),
|
||||
background: path.join(src, 'background'),
|
||||
console: path.join(src, 'pages', 'console.js')
|
||||
console: path.join(src, 'console')
|
||||
},
|
||||
|
||||
output: {
|
||||
|
@ -45,7 +45,7 @@ module.exports = {
|
|||
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
template: path.join(src, 'pages', 'console.html'),
|
||||
template: path.join(src, 'console', 'index.html'),
|
||||
filename: path.join(dist, 'console.html'),
|
||||
inject: false
|
||||
}),
|
||||
|
|
Reference in a new issue