parent
98bc2326ee
commit
2c366ac3b1
8 changed files with 64 additions and 15 deletions
@ -0,0 +1,17 @@ |
|||||||
|
import * as tabActions from '../actions/tab'; |
||||||
|
|
||||||
|
export default class TabComponent { |
||||||
|
constructor(store) { |
||||||
|
this.store = store; |
||||||
|
|
||||||
|
browser.tabs.onActivated.addListener((info) => { |
||||||
|
return browser.tabs.query({ currentWindow: true }).then(() => { |
||||||
|
return this.onTabActivated(info); |
||||||
|
}); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
onTabActivated(info) { |
||||||
|
return this.store.dispatch(tabActions.selected(info.tabId)); |
||||||
|
} |
||||||
|
} |
@ -1,15 +1,18 @@ |
|||||||
import settingReducer from './setting'; |
import settingReducer from './setting'; |
||||||
import findReducer from './find'; |
import findReducer from './find'; |
||||||
|
import tabReducer from './tab'; |
||||||
|
|
||||||
// Make setting reducer instead of re-use
|
// Make setting reducer instead of re-use
|
||||||
const defaultState = { |
const defaultState = { |
||||||
setting: settingReducer(undefined, {}), |
setting: settingReducer(undefined, {}), |
||||||
find: findReducer(undefined, {}), |
find: findReducer(undefined, {}), |
||||||
|
tab: tabReducer(undefined, {}), |
||||||
}; |
}; |
||||||
|
|
||||||
export default function reducer(state = defaultState, action = {}) { |
export default function reducer(state = defaultState, action = {}) { |
||||||
return Object.assign({}, state, { |
return Object.assign({}, state, { |
||||||
setting: settingReducer(state.setting, action), |
setting: settingReducer(state.setting, action), |
||||||
find: findReducer(state.find, action), |
find: findReducer(state.find, action), |
||||||
|
tab: tabReducer(state.tab, action), |
||||||
}); |
}); |
||||||
} |
} |
||||||
|
@ -0,0 +1,19 @@ |
|||||||
|
import actions from 'background/actions'; |
||||||
|
|
||||||
|
const defaultState = { |
||||||
|
previousSelected: -1, |
||||||
|
currentSelected: -1, |
||||||
|
}; |
||||||
|
|
||||||
|
export default function reducer(state = defaultState, action = {}) { |
||||||
|
switch (action.type) { |
||||||
|
case actions.TAB_SELECTED: |
||||||
|
return { |
||||||
|
previousSelected: state.currentSelected, |
||||||
|
currentSelected: action.tabId, |
||||||
|
}; |
||||||
|
default: |
||||||
|
return state; |
||||||
|
} |
||||||
|
} |
||||||
|
|
Reference in new issue