move background actions to operations
This commit is contained in:
		
							parent
							
								
									0ae39f1b67
								
							
						
					
					
						commit
						b6e5153c1f
					
				
					 6 changed files with 56 additions and 33 deletions
				
			
		| 
						 | 
					@ -7,14 +7,6 @@ export default {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Background commands
 | 
					  // Background commands
 | 
				
			||||||
  BACKGROUND_REQUEST_COMPLETIONS: 'vimvixen.background.request.completions',
 | 
					  BACKGROUND_REQUEST_COMPLETIONS: 'vimvixen.background.request.completions',
 | 
				
			||||||
  TABS_CLOSE: 'tabs.close',
 | 
					 | 
				
			||||||
  TABS_REOPEN: 'tabs.reopen',
 | 
					 | 
				
			||||||
  TABS_PREV: 'tabs.prev',
 | 
					 | 
				
			||||||
  TABS_NEXT: 'tabs.next',
 | 
					 | 
				
			||||||
  TABS_RELOAD: 'tabs.reload',
 | 
					 | 
				
			||||||
  ZOOM_IN: 'zoom.in',
 | 
					 | 
				
			||||||
  ZOOM_OUT: 'zoom.out',
 | 
					 | 
				
			||||||
  ZOOM_NEUTRAL: 'zoom.neutral',
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // content commands
 | 
					  // content commands
 | 
				
			||||||
  CMD_OPEN: 'cmd.open',
 | 
					  CMD_OPEN: 'cmd.open',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										27
									
								
								src/actions/operation.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/actions/operation.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,27 @@
 | 
				
			||||||
 | 
					import operations from '../operations';
 | 
				
			||||||
 | 
					import * as tabs from '../background/tabs';
 | 
				
			||||||
 | 
					import * as zooms from '../background/zooms';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function exec(operation, sender) {
 | 
				
			||||||
 | 
					  switch (operation.type) {
 | 
				
			||||||
 | 
					  case operations.TABS_CLOSE:
 | 
				
			||||||
 | 
					    return tabs.closeTab(sender.tab.id);
 | 
				
			||||||
 | 
					  case operations.TABS_REOPEN:
 | 
				
			||||||
 | 
					    return tabs.reopenTab();
 | 
				
			||||||
 | 
					  case operations.TABS_PREV:
 | 
				
			||||||
 | 
					    return tabs.selectPrevTab(sender.tab.index, operation.count);
 | 
				
			||||||
 | 
					  case operations.TABS_NEXT:
 | 
				
			||||||
 | 
					    return tabs.selectNextTab(sender.tab.index, operation.count);
 | 
				
			||||||
 | 
					  case operations.TABS_RELOAD:
 | 
				
			||||||
 | 
					    return tabs.reload(sender.tab, operation.cache);
 | 
				
			||||||
 | 
					  case operations.ZOOM_IN:
 | 
				
			||||||
 | 
					    return zooms.zoomIn();
 | 
				
			||||||
 | 
					  case operations.ZOOM_OUT:
 | 
				
			||||||
 | 
					    return zooms.zoomOut();
 | 
				
			||||||
 | 
					  case operations.ZOOM_NEUTRAL:
 | 
				
			||||||
 | 
					    return zooms.neutral();
 | 
				
			||||||
 | 
					  default:
 | 
				
			||||||
 | 
					    return Promise.resolve();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,15 @@
 | 
				
			||||||
import * as keys from './keys';
 | 
					import * as keys from './keys';
 | 
				
			||||||
import * as inputActions from '../actions/input';
 | 
					import * as inputActions from '../actions/input';
 | 
				
			||||||
 | 
					import * as operationActions from '../actions/operation';
 | 
				
			||||||
import backgroundReducers from '../reducers/background';
 | 
					import backgroundReducers from '../reducers/background';
 | 
				
			||||||
import commandReducer from '../reducers/command';
 | 
					import commandReducer from '../reducers/command';
 | 
				
			||||||
import inputReducers from '../reducers/input';
 | 
					import inputReducers from '../reducers/input';
 | 
				
			||||||
 | 
					import * as store from '../store'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const emptyReducer = (state, action) => state;
 | 
				
			||||||
 | 
					const emptyStore = store.createStore(emptyReducer, (e) => {
 | 
				
			||||||
 | 
					  console.error('Vim-Vixen:', e);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
let inputState = inputReducers(undefined, {});
 | 
					let inputState = inputReducers(undefined, {});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const keyQueueChanged = (sender, prevState, state) => {
 | 
					const keyQueueChanged = (sender, prevState, state) => {
 | 
				
			||||||
| 
						 | 
					@ -21,6 +27,9 @@ const keyQueueChanged = (sender, prevState, state) => {
 | 
				
			||||||
    return Promise.resolve();
 | 
					    return Promise.resolve();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  let action = keys.defaultKeymap[matched];
 | 
					  let action = keys.defaultKeymap[matched];
 | 
				
			||||||
 | 
					  emptyStore.dispatch(operationActions.exec(action, sender), (e) => {
 | 
				
			||||||
 | 
					    console.error('Vim-Vixen:', e);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
  return handleMessage(inputActions.clearKeys(), sender).then(() => {
 | 
					  return handleMessage(inputActions.clearKeys(), sender).then(() => {
 | 
				
			||||||
    return backgroundReducers(undefined, action, sender).then(() => {
 | 
					    return backgroundReducers(undefined, action, sender).then(() => {
 | 
				
			||||||
      return browser.tabs.sendMessage(sender.tab.id, action);
 | 
					      return browser.tabs.sendMessage(sender.tab.id, action);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
import actions from '../actions';
 | 
					import actions from '../actions';
 | 
				
			||||||
 | 
					import operations from '../operations';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const defaultKeymap = {
 | 
					const defaultKeymap = {
 | 
				
			||||||
  ':': { type: actions.CMD_OPEN },
 | 
					  ':': { type: actions.CMD_OPEN },
 | 
				
			||||||
| 
						 | 
					@ -17,15 +18,15 @@ const defaultKeymap = {
 | 
				
			||||||
  'G': { type: actions.SCROLL_BOTTOM },
 | 
					  'G': { type: actions.SCROLL_BOTTOM },
 | 
				
			||||||
  '0': { type: actions.SCROLL_LEFT },
 | 
					  '0': { type: actions.SCROLL_LEFT },
 | 
				
			||||||
  '$': { type: actions.SCROLL_RIGHT },
 | 
					  '$': { type: actions.SCROLL_RIGHT },
 | 
				
			||||||
  'd': { type: actions.TABS_CLOSE },
 | 
					  'd': { type: operations.TABS_CLOSE },
 | 
				
			||||||
  'u': { type: actions.TABS_REOPEN },
 | 
					  'u': { type: operations.TABS_REOPEN },
 | 
				
			||||||
  'h': { type: actions.TABS_PREV, count: 1 },
 | 
					  'h': { type: operations.TABS_PREV, count: 1 },
 | 
				
			||||||
  'l': { type: actions.TABS_NEXT, count: 1 },
 | 
					  'l': { type: operations.TABS_NEXT, count: 1 },
 | 
				
			||||||
  'r': { type: actions.TABS_RELOAD, cache: false },
 | 
					  'r': { type: operations.TABS_RELOAD, cache: false },
 | 
				
			||||||
  'R': { type: actions.TABS_RELOAD, cache: true },
 | 
					  'R': { type: operations.TABS_RELOAD, cache: true },
 | 
				
			||||||
  'zi': { type: actions.ZOOM_IN },
 | 
					  'zi': { type: operations.ZOOM_IN },
 | 
				
			||||||
  'zo': { type: actions.ZOOM_OUT },
 | 
					  'zo': { type: operations.ZOOM_OUT },
 | 
				
			||||||
  'zz': { type: actions.ZOOM_NEUTRAL },
 | 
					  'zz': { type: operations.ZOOM_NEUTRAL },
 | 
				
			||||||
  'f': { type: actions.FOLLOW_START, newTab: false },
 | 
					  'f': { type: actions.FOLLOW_START, newTab: false },
 | 
				
			||||||
  'F': { type: actions.FOLLOW_START, newTab: true },
 | 
					  'F': { type: actions.FOLLOW_START, newTab: true },
 | 
				
			||||||
  'H': { type: actions.HISTORY_PREV },
 | 
					  'H': { type: actions.HISTORY_PREV },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								src/operations/index.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/operations/index.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					export default {
 | 
				
			||||||
 | 
					  TABS_CLOSE: 'tabs.close',
 | 
				
			||||||
 | 
					  TABS_REOPEN: 'tabs.reopen',
 | 
				
			||||||
 | 
					  TABS_PREV: 'tabs.prev',
 | 
				
			||||||
 | 
					  TABS_NEXT: 'tabs.next',
 | 
				
			||||||
 | 
					  TABS_RELOAD: 'tabs.reload',
 | 
				
			||||||
 | 
					  ZOOM_IN: 'zoom.in',
 | 
				
			||||||
 | 
					  ZOOM_OUT: 'zoom.out',
 | 
				
			||||||
 | 
					  ZOOM_NEUTRAL: 'zoom.neutral',
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -31,22 +31,6 @@ export default function reducer(state, action = {}, sender) {
 | 
				
			||||||
  switch (action.type) {
 | 
					  switch (action.type) {
 | 
				
			||||||
  case actions.BACKGROUND_REQUEST_COMPLETIONS:
 | 
					  case actions.BACKGROUND_REQUEST_COMPLETIONS:
 | 
				
			||||||
    return doCompletion(action.command, action.keywords, sender.tab.id);
 | 
					    return doCompletion(action.command, action.keywords, sender.tab.id);
 | 
				
			||||||
  case actions.TABS_CLOSE:
 | 
					 | 
				
			||||||
    return tabs.closeTab(sender.tab.id);
 | 
					 | 
				
			||||||
  case actions.TABS_REOPEN:
 | 
					 | 
				
			||||||
    return tabs.reopenTab();
 | 
					 | 
				
			||||||
  case actions.TABS_PREV:
 | 
					 | 
				
			||||||
    return tabs.selectPrevTab(sender.tab.index, action.count);
 | 
					 | 
				
			||||||
  case actions.TABS_NEXT:
 | 
					 | 
				
			||||||
    return tabs.selectNextTab(sender.tab.index, action.count);
 | 
					 | 
				
			||||||
  case actions.TABS_RELOAD:
 | 
					 | 
				
			||||||
    return tabs.reload(sender.tab, action.cache);
 | 
					 | 
				
			||||||
  case actions.ZOOM_IN:
 | 
					 | 
				
			||||||
    return zooms.zoomIn();
 | 
					 | 
				
			||||||
  case actions.ZOOM_OUT:
 | 
					 | 
				
			||||||
    return zooms.zoomOut();
 | 
					 | 
				
			||||||
  case actions.ZOOM_NEUTRAL:
 | 
					 | 
				
			||||||
    return zooms.neutral();
 | 
					 | 
				
			||||||
  default:
 | 
					  default:
 | 
				
			||||||
    return Promise.resolve();
 | 
					    return Promise.resolve();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue