[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 messages from 'content/messages'; | ||||
| import * as consoleActions from './console'; | ||||
| import * as tabs from 'background/tabs'; | ||||
| 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) => { | ||||
|   switch (operation.type) { | ||||
|   case operations.TAB_CLOSE: | ||||
|  | @ -23,21 +29,21 @@ const exec = (operation, tab) => { | |||
|   case operations.ZOOM_NEUTRAL: | ||||
|     return zooms.neutral(); | ||||
|   case operations.COMMAND_SHOW: | ||||
|     return consoleActions.showCommand(''); | ||||
|     return sendConsoleShowCommand(tab, ''); | ||||
|   case operations.COMMAND_SHOW_OPEN: | ||||
|     if (operation.alter) { | ||||
|       // 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: | ||||
|     if (operation.alter) { | ||||
|       // 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: | ||||
|     return consoleActions.showCommand('buffer '); | ||||
|     return sendConsoleShowCommand(tab, 'buffer '); | ||||
|   default: | ||||
|     return browser.tabs.sendMessage(tab.id, { | ||||
|       type: messages.CONTENT_OPERATION, | ||||
|  |  | |||
|  | @ -3,7 +3,6 @@ import * as settingsActions from 'actions/setting'; | |||
| import BackgroundComponent from 'components/background'; | ||||
| import BackgroundInputComponent from 'components/background-input'; | ||||
| import reducers from 'reducers'; | ||||
| import messages from 'content/messages'; | ||||
| import { createStore } from 'store'; | ||||
| 
 | ||||
| const store = createStore(reducers, (e, sender) => { | ||||
|  | @ -18,13 +17,5 @@ store.subscribe((sender) => { | |||
|   backgroundComponent.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()); | ||||
|  |  | |||
|  | @ -70,8 +70,8 @@ export default class ConsoleComponent { | |||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   // TODO use store/reducer to update state.  
 | ||||
|   update(state) { | ||||
|   update() { | ||||
|     let state = this.store.getState().console; | ||||
|     if (!this.prevState.commandShown && state.commandShown) { | ||||
|       this.showCommand(state.commandText); | ||||
|     } 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) => { | ||||
|   switch (action.type) { | ||||
|   case messages.STATE_UPDATE: | ||||
|     return update(action.state); | ||||
|   case messages.CONSOLE_HIDE: | ||||
|     window.focus(); | ||||
|     consoleFrames.blur(window.document); | ||||
|     return Promise.resolve(); | ||||
|   case messages.CONTENT_OPERATION: | ||||
|     execOperation(action.operation); | ||||
|     return Promise.resolve(); | ||||
|  |  | |||
|  | @ -1,10 +1,12 @@ | |||
| export default { | ||||
|   STATE_UPDATE: 'state.update', | ||||
|   CONTENT_OPERATION: 'content.operation', | ||||
| 
 | ||||
|   CONSOLE_BLURRED: 'console.blured', | ||||
|   CONSOLE_ENTERED: 'console.entered', | ||||
|   CONSOLE_QUERY_COMPLETIONS: 'console.query.completions', | ||||
|   CONSOLE_SHOW_COMMAND: 'console.show.command', | ||||
|   CONSOLE_SHOW_ERROR: 'console.show.error', | ||||
|   CONSOLE_HIDE: 'console.hide', | ||||
| 
 | ||||
|   KEYDOWN: 'keydown', | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ import CompletionComponent from 'components/completion'; | |||
| import ConsoleComponent from 'components/console'; | ||||
| import reducers from 'reducers'; | ||||
| import { createStore } from 'store'; | ||||
| import * as completionActions from 'actions/completion'; | ||||
| import * as consoleActions from 'actions/console'; | ||||
| 
 | ||||
| const store = createStore(reducers); | ||||
| let completionComponent = null; | ||||
|  | @ -20,6 +20,7 @@ window.addEventListener('load', () => { | |||
| 
 | ||||
| store.subscribe(() => { | ||||
|   completionComponent.update(); | ||||
|   consoleComponent.update(); | ||||
| 
 | ||||
|   let state = store.getState().completion; | ||||
| 
 | ||||
|  | @ -36,8 +37,12 @@ store.subscribe(() => { | |||
| }); | ||||
| 
 | ||||
| browser.runtime.onMessage.addListener((action) => { | ||||
|   if (action.type === messages.STATE_UPDATE) { | ||||
|     let state = action.state.console; | ||||
|     consoleComponent.update(state); | ||||
|   switch (action.type) { | ||||
|   case messages.CONSOLE_SHOW_COMMAND: | ||||
|     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