Skip to content
This repository has been archived by the owner. It is now read-only.

first pass at action consolidation for urlbar #8368

Merged
merged 1 commit into from May 4, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

first pass at action consolidation for urlbar

  • Loading branch information
bridiver committed Apr 18, 2017
commit e5d2de407814bca1f877766e99dcc0623bfe1bd4
@@ -34,14 +34,14 @@ const api = {
// in WindowState
const index = state.get('frames').findIndex((frame) => frame.get('key') === frameKey)
if (index === -1) {
return path.concat('nosuchframe')
return null
}
return path.concat(['frames', index])
} else {
// in AppState
const index = state.get('tabs').findIndex((tab) => tab.getIn(['frame', 'key']) === frameKey)
if (index === -1) {
return path.concat('nosuchtab')
return null
}
return makeImmutable(['tabs', index, 'frame'])
}
@@ -61,21 +61,33 @@ const api = {
// in WindowState
const index = state.get('frames').findIndex((frame) => frame.get('tabId') === tabId)
if (index === -1) {
return makeImmutable(['nosuchframe'])
return null
}
return path.concat(['frames', index])
},

getByFrameKey: (state, frameKey) => {
return state.getIn(api.getPathByFrameKey(state, frameKey))
const path = api.getPathByFrameKey(state, frameKey)
if (path == null) {
return null
}
return state.getIn(path)
},

getByTabId: (state, tabId) => {
return state.getIn(api.getPathByTabId(state, tabId))
const path = api.getPathByTabId(state, tabId)
if (path == null) {
return null
}
return state.getIn(path)
},

getTabIdByFrameKey: (state, frameKey) => {
return state.getIn(api.getPathByFrameKey(state, frameKey).concat('tabId')) || -1
const path = api.getPathByFrameKey(state, frameKey)
if (path == null) {
return null
}
return state.getIn(path.concat('tabId')) || -1
}
}

@@ -40,7 +40,11 @@ const api = {
state = validateState(state)
tabState.validateTabId(tabId)

return tabState.getFramePathByTabId(state, tabId).concat('navbar')
const path = tabState.getFramePathByTabId(state, tabId)
if (path == null) {
return null
}
return path.push('navbar')
},

getNavigationBar: (state, tabId) => {
@@ -51,15 +55,25 @@ const api = {
return defaultState
}

return state.getIn(api.getNavigationBarPath(state, tabId)) || defaultState
const path = api.getNavigationBarPath(state, tabId)
if (path == null) {
return defaultState
}

return state.getIn(path) || defaultState
},

getUrlBarPath: (state, tabId) => {
return api.getNavigationBarPath(state, tabId).concat('urlbar')
const path = api.getNavigationBarPath(state, tabId)
return path == null ? null : path.push('urlbar')
},

getUrlBar: (state, tabId) => {
return state.getIn(api.getUrlBarPath(state, tabId)) || defaultState.get('urlbar')
const path = api.getUrlBarPath(state, tabId)
if (path == null) {
return defaultState.get('urlbar')
}
return state.getIn(path) || defaultState.get('urlbar')
},

locationValueSuffix: (state, tabId) => {
@@ -103,7 +117,11 @@ const api = {

setSelectedIndex: (state, tabId, index = -1) => {
state = validateState(state)
return state.setIn(api.getUrlBarPath(state, tabId).concat(['suggestions', 'selectedIndex']), index)
const path = api.getUrlBarPath(state, tabId)
if (path == null) {
return state
}
return state.setIn(path.concat(['suggestions', 'selectedIndex']), index)
},

getSelectedIndex: (state, tabId) => {
@@ -113,8 +131,12 @@ const api = {

setSuggestionList: (state, tabId, suggestionList = []) => {
state = validateState(state)
const path = api.getUrlBarPath(state, tabId)
if (path == null) {
return state
}
suggestionList = makeImmutable(suggestionList)
return state.setIn(api.getUrlBarPath(state, tabId).concat(['suggestions', 'suggestionList']), suggestionList)
return state.setIn(path.concat(['suggestions', 'suggestionList']), suggestionList)
},

getSuggestionList: (state, tabId) => {
@@ -133,7 +155,11 @@ const api = {

setAutocompleteEnabled: (state, tabId, enabled = false) => {
state = validateState(state)
return state.setIn(api.getUrlBarPath(state, tabId).concat(['suggestions', 'autocompleteEnabled']), enabled)
const path = api.getUrlBarPath(state, tabId)
if (path == null) {
return state
}
return state.setIn(path.concat(['suggestions', 'autocompleteEnabled']), enabled)
},

isAutocompleteEnabled: (state, tabId) => {
@@ -142,16 +168,25 @@ const api = {

setLocation: (state, tabId, location, counter) => {
state = validateState(state)
return state.setIn(api.getUrlBarPath(state, tabId).push('location'), location)
const path = api.getUrlBarPath(state, tabId)
if (path == null) {
return state
}
return state.setIn(path.push('location'), location)
},

getLocation: (state, tabId) => {
return api.getUrlBar(state, tabId).get('location')
},

setKeyCounter: (state, tabId, counter) => {
const path = api.getUrlBarPath(state, tabId)
if (path == null) {
return state
}

if (counter) {
state = state.setIn(api.getUrlBarPath(state, tabId).push('keyCounter'), counter)
state = state.setIn(path.push('keyCounter'), counter)
}
return state
},
@@ -162,9 +197,13 @@ const api = {

setShouldRenderUrlBarSuggestions: (state, tabId, enabled = false) => {
state = validateState(state)
state = state.setIn(api.getUrlBarPath(state, tabId).concat(['suggestions', 'shouldRender']), enabled)
const path = api.getUrlBarPath(state, tabId)
if (path == null) {
return state
}
state = state.setIn(path.concat(['suggestions', 'shouldRender']), enabled)
if (!enabled) {
state = state.mergeIn(api.getUrlBarPath(state, tabId).push('suggestions'), defaultState.getIn(['urlbar', 'suggestions']))
state = state.mergeIn(path.push('suggestions'), defaultState.getIn(['urlbar', 'suggestions']))
}
return state
},
@@ -175,39 +214,13 @@ const api = {
suggestionList && suggestionList.size > 0
},

setPreviousUrlBarSuggestionSelected: (state, tabId) => {
if (api.shouldRenderUrlBarSuggestions(state, tabId)) {
const selectedIndex = api.getSelectedIndex(state, tabId)
const lastSuffix = api.locationValueSuffix(state, tabId)

if (selectedIndex !== 0 && !lastSuffix) {
state = api.setSelectedIndex(state, tabId, 0)
} else if (selectedIndex > 0) {
state = api.setSelectedIndex(state, tabId, selectedIndex - 1)
}
// state = updateUrlSuffix(state, state.getIn(activeFrameStatePath(state).concat(['navbar', 'urlbar', 'suggestions', 'suggestionList']), suggestionList))
}
return state
},

setNextUrlBarSuggestionSelected: (state, tabId) => {
if (api.shouldRenderUrlBarSuggestions(state, tabId)) {
const selectedIndex = api.getSelectedIndex(state, tabId)
const lastSuffix = api.locationValueSuffix(state, tabId)

if (selectedIndex !== 0 && !lastSuffix) {
state = api.setSelectedIndex(state, tabId, 0)
} else if (selectedIndex > 0) {
state = api.setSelectedIndex(state, tabId, selectedIndex - 1)
}
// state = updateUrlSuffix(state, state.getIn(activeFrameStatePath(state).concat(['navbar', 'urlbar', 'suggestions', 'suggestionList']), suggestionList))
}
return state
},

setActive: (state, tabId, active = false) => {
state = validateState(state)
return state.setIn(api.getUrlBarPath(state, tabId).push('active'), active)
const path = api.getUrlBarPath(state, tabId)
if (path == null) {
return state
}
return state.setIn(path.push('active'), active)
},

isActive: (state, tabId) => {
@@ -216,7 +229,11 @@ const api = {

setFocused: (state, tabId, focused = false) => {
state = validateState(state)
return state.setIn(api.getUrlBarPath(state, tabId).push('focused'), focused)
const path = api.getUrlBarPath(state, tabId)
if (path == null) {
return state
}
return state.setIn(path.push('focused'), focused)
},

isFocused: (state, tabId) => {
@@ -225,11 +242,15 @@ const api = {

setSelected: (state, tabId, selected = false) => {
state = validateState(state)
const path = api.getUrlBarPath(state, tabId)
if (path == null) {
return state
}
if (selected) {
// selection implies focus
state = state = api.setFocused(state, tabId, true)
}
return state.setIn(api.getUrlBarPath(state, tabId).push('selected'), selected)
return state.setIn(path.push('selected'), selected)
},

isSelected: (state, tabId) => {
@@ -171,8 +171,8 @@ const tabState = {
state = validateState(state)

const index = state.get('tabs').findIndex((tab) => tab.get('tabId') === tabId)
if (index === -1) {
return makeImmutable(['nosuchpath'])
if (index === tabState.TAB_ID_NONE) {
return null
}
return makeImmutable(['tabs', index])
},
@@ -185,7 +185,11 @@ const tabState = {
return null
}

return state.getIn(tabState.getPathByTabId(state, tabId))
const path = tabState.getPathByTabId(state, tabId)
if (path == null) {
return null
}
return state.getIn(path)
},

getTab: (state, tabValue) => {
@@ -305,8 +309,17 @@ const tabState = {
getFramePathByTabId: (state, tabId) => {
state = makeImmutable(state)
tabId = validateId('tabId', tabId)
if (state.get('tabs')) {
return tabState.getPathByTabId(state, tabId).push('frame')

if (tabId === tabState.TAB_ID_NONE) {
return null
}

if (state.get('tabs') && !state.get('frames')) {
const path = tabState.getPathByTabId(state, tabId)
if (path == null) {
return null
}
return path.push('frame')
} else {
return frameState.getPathByTabId(state, tabId)
}
@@ -324,32 +337,36 @@ const tabState = {
},

getFrameByTabId: (state, tabId) => {
const path = tabState.getFramePathByTabId(state, tabId)
if (path == null) {
return null
}
return state.getIn(tabState.getFramePathByTabId(state, tabId))
},

isSecure: (state, tabId) => {
const frame = tabState.getFrameByTabId(state, tabId)
return frameStateUtil.isFrameSecure(frame)
return frame ? frameStateUtil.isFrameSecure(frame) : null
},

isLoading: (state, tabId) => {
const frame = tabState.getFrameByTabId(state, tabId)
return frameStateUtil.isFrameLoading(frame)
return frame ? frameStateUtil.isFrameLoading(frame) : null
},

startLoadTime: (state, tabId) => {
const frame = tabState.getFrameByTabId(state, tabId)
return frameStateUtil.startLoadTime(frame)
return frame ? frameStateUtil.startLoadTime(frame) : null
},

endLoadTime: (state, tabId) => {
const frame = tabState.getFrameByTabId(state, tabId)
return frameStateUtil.endLoadTime(frame)
return frame ? frameStateUtil.endLoadTime(frame) : null
},

getHistory: (state, tabId) => {
const frame = tabState.getFrameByTabId(state, tabId)
return frameStateUtil.getHistory(frame)
return frame ? frameStateUtil.getHistory(frame) : null
},

getLocation: (state, tabId) => {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.