[wip] remove STATE_UPDATE
This commit is contained in:
parent
10ad62e606
commit
4cb17031d1
6 changed files with 31 additions and 32 deletions
|
@ -1,9 +1,15 @@
|
||||||
import operations from 'shared/operations';
|
import operations from 'shared/operations';
|
||||||
import messages from 'content/messages';
|
import messages from 'content/messages';
|
||||||
import * as consoleActions from './console';
|
|
||||||
import * as tabs from 'background/tabs';
|
import * as tabs from 'background/tabs';
|
||||||
import * as zooms from 'background/zooms';
|
import * as zooms from 'background/zooms';
|
||||||
|
|
||||||
|
const sendConsoleShowCommand = (tab, command) => {
|
||||||
|
return browser.tabs.sendMessage(tab.id, {
|
||||||
|
type: messages.CONSOLE_SHOW_COMMAND,
|
||||||
|
command,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const exec = (operation, tab) => {
|
const exec = (operation, tab) => {
|
||||||
switch (operation.type) {
|
switch (operation.type) {
|
||||||
case operations.TAB_CLOSE:
|
case operations.TAB_CLOSE:
|
||||||
|
@ -23,21 +29,21 @@ const exec = (operation, tab) => {
|
||||||
case operations.ZOOM_NEUTRAL:
|
case operations.ZOOM_NEUTRAL:
|
||||||
return zooms.neutral();
|
return zooms.neutral();
|
||||||
case operations.COMMAND_SHOW:
|
case operations.COMMAND_SHOW:
|
||||||
return consoleActions.showCommand('');
|
return sendConsoleShowCommand(tab, '');
|
||||||
case operations.COMMAND_SHOW_OPEN:
|
case operations.COMMAND_SHOW_OPEN:
|
||||||
if (operation.alter) {
|
if (operation.alter) {
|
||||||
// alter url
|
// alter url
|
||||||
return consoleActions.showCommand('open ' + tab.url);
|
return sendConsoleShowCommand(tab, 'open ' + tab.url);
|
||||||
}
|
}
|
||||||
return consoleActions.showCommand('open ');
|
return sendConsoleShowCommand(tab, 'open ');
|
||||||
case operations.COMMAND_SHOW_TABOPEN:
|
case operations.COMMAND_SHOW_TABOPEN:
|
||||||
if (operation.alter) {
|
if (operation.alter) {
|
||||||
// alter url
|
// alter url
|
||||||
return consoleActions.showCommand('tabopen ' + tab.url);
|
return sendConsoleShowCommand(tab, 'tabopen ' + tab.url);
|
||||||
}
|
}
|
||||||
return consoleActions.showCommand('tabopen ');
|
return sendConsoleShowCommand(tab, 'tabopen ');
|
||||||
case operations.COMMAND_SHOW_BUFFER:
|
case operations.COMMAND_SHOW_BUFFER:
|
||||||
return consoleActions.showCommand('buffer ');
|
return sendConsoleShowCommand(tab, 'buffer ');
|
||||||
default:
|
default:
|
||||||
return browser.tabs.sendMessage(tab.id, {
|
return browser.tabs.sendMessage(tab.id, {
|
||||||
type: messages.CONTENT_OPERATION,
|
type: messages.CONTENT_OPERATION,
|
||||||
|
|
|
@ -3,7 +3,6 @@ import * as settingsActions from 'actions/setting';
|
||||||
import BackgroundComponent from 'components/background';
|
import BackgroundComponent from 'components/background';
|
||||||
import BackgroundInputComponent from 'components/background-input';
|
import BackgroundInputComponent from 'components/background-input';
|
||||||
import reducers from 'reducers';
|
import reducers from 'reducers';
|
||||||
import messages from 'content/messages';
|
|
||||||
import { createStore } from 'store';
|
import { createStore } from 'store';
|
||||||
|
|
||||||
const store = createStore(reducers, (e, sender) => {
|
const store = createStore(reducers, (e, sender) => {
|
||||||
|
@ -18,13 +17,5 @@ store.subscribe((sender) => {
|
||||||
backgroundComponent.update(sender);
|
backgroundComponent.update(sender);
|
||||||
backgroundInputComponent.update(sender);
|
backgroundInputComponent.update(sender);
|
||||||
});
|
});
|
||||||
store.subscribe((sender) => {
|
|
||||||
if (sender) {
|
|
||||||
return browser.tabs.sendMessage(sender.tab.id, {
|
|
||||||
type: messages.STATE_UPDATE,
|
|
||||||
state: store.getState()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
store.dispatch(settingsActions.load());
|
store.dispatch(settingsActions.load());
|
||||||
|
|
|
@ -70,8 +70,8 @@ export default class ConsoleComponent {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO use store/reducer to update state.
|
update() {
|
||||||
update(state) {
|
let state = this.store.getState().console;
|
||||||
if (!this.prevState.commandShown && state.commandShown) {
|
if (!this.prevState.commandShown && state.commandShown) {
|
||||||
this.showCommand(state.commandText);
|
this.showCommand(state.commandText);
|
||||||
} else if (!state.commandShown) {
|
} else if (!state.commandShown) {
|
||||||
|
|
|
@ -55,17 +55,12 @@ const execOperation = (operation) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const update = (state) => {
|
|
||||||
if (!state.console.commandShown) {
|
|
||||||
window.focus();
|
|
||||||
consoleFrames.blur(window.document);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener((action) => {
|
browser.runtime.onMessage.addListener((action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case messages.STATE_UPDATE:
|
case messages.CONSOLE_HIDE:
|
||||||
return update(action.state);
|
window.focus();
|
||||||
|
consoleFrames.blur(window.document);
|
||||||
|
return Promise.resolve();
|
||||||
case messages.CONTENT_OPERATION:
|
case messages.CONTENT_OPERATION:
|
||||||
execOperation(action.operation);
|
execOperation(action.operation);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
export default {
|
export default {
|
||||||
STATE_UPDATE: 'state.update',
|
|
||||||
CONTENT_OPERATION: 'content.operation',
|
CONTENT_OPERATION: 'content.operation',
|
||||||
|
|
||||||
CONSOLE_BLURRED: 'console.blured',
|
CONSOLE_BLURRED: 'console.blured',
|
||||||
CONSOLE_ENTERED: 'console.entered',
|
CONSOLE_ENTERED: 'console.entered',
|
||||||
CONSOLE_QUERY_COMPLETIONS: 'console.query.completions',
|
CONSOLE_QUERY_COMPLETIONS: 'console.query.completions',
|
||||||
|
CONSOLE_SHOW_COMMAND: 'console.show.command',
|
||||||
|
CONSOLE_SHOW_ERROR: 'console.show.error',
|
||||||
|
CONSOLE_HIDE: 'console.hide',
|
||||||
|
|
||||||
KEYDOWN: 'keydown',
|
KEYDOWN: 'keydown',
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import CompletionComponent from 'components/completion';
|
||||||
import ConsoleComponent from 'components/console';
|
import ConsoleComponent from 'components/console';
|
||||||
import reducers from 'reducers';
|
import reducers from 'reducers';
|
||||||
import { createStore } from 'store';
|
import { createStore } from 'store';
|
||||||
import * as completionActions from 'actions/completion';
|
import * as consoleActions from 'actions/console';
|
||||||
|
|
||||||
const store = createStore(reducers);
|
const store = createStore(reducers);
|
||||||
let completionComponent = null;
|
let completionComponent = null;
|
||||||
|
@ -20,6 +20,7 @@ window.addEventListener('load', () => {
|
||||||
|
|
||||||
store.subscribe(() => {
|
store.subscribe(() => {
|
||||||
completionComponent.update();
|
completionComponent.update();
|
||||||
|
consoleComponent.update();
|
||||||
|
|
||||||
let state = store.getState().completion;
|
let state = store.getState().completion;
|
||||||
|
|
||||||
|
@ -36,8 +37,12 @@ store.subscribe(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener((action) => {
|
browser.runtime.onMessage.addListener((action) => {
|
||||||
if (action.type === messages.STATE_UPDATE) {
|
switch (action.type) {
|
||||||
let state = action.state.console;
|
case messages.CONSOLE_SHOW_COMMAND:
|
||||||
consoleComponent.update(state);
|
return store.dispatch(consoleActions.showCommand(action.command));
|
||||||
|
case messages.CONSOLE_SHOW_ERROR:
|
||||||
|
return store.dispatch(consoleActions.showError(action.command));
|
||||||
|
case messages.CONSOLE_HIDE:
|
||||||
|
return store.dispatch(consoleActions.hide(action.command));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue