Skip to content

Instantly share code, notes, and snippets.

@jdmorlan
Created September 23, 2016 23:28
Show Gist options
  • Save jdmorlan/4f9f23eaacf9a36d730ea84c21cbdc71 to your computer and use it in GitHub Desktop.
Save jdmorlan/4f9f23eaacf9a36d730ea84c21cbdc71 to your computer and use it in GitHub Desktop.
export const goTo = (viewName, opts = {}) => {
return (dispatch, getState) => {
const tabName = opts['tabName']
const params = opts['params']
const goingBack = opts['goingBack']
const state = getState()
const currentTab = getCurrentTab(state)
let view
if (tabName === undefined) {
view = currentTab.views[viewName]
} else {
const tab = getTab(state, tabName)
view = tab.views[viewName]
}
const enhancedView = { ...view, params }
if (view.historical && !goingBack) {
dispatch(addHistoryItem(currentTab.id, currentTab.currentView))
}
store.dispatch(setCurrentView(currentTab.id, enhancedView))
store.dispatch(setNavHeaderVisibility(view.navHeaderVisible))
store.dispatch(setTabBarVisibility(view.tabBarVisible))
const formattedRoute = formatPatter(enhancedView.path, enhancedView.params)
dispatch(push(formattedRoute))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment