Skip to content

Instantly share code, notes, and snippets.

@hipertracker
Created July 5, 2017 15:26
Show Gist options
  • Select an option

  • Save hipertracker/4518955fe355de10b65fe43058ef3d74 to your computer and use it in GitHub Desktop.

Select an option

Save hipertracker/4518955fe355de10b65fe43058ef3d74 to your computer and use it in GitHub Desktop.
Cerebral 2 sequences
import { sequence } from 'cerebral'
import { set, when } from 'cerebral/operators'
import { state, props } from 'cerebral/tags'
import { httpGet } from '@cerebral/http/operators'
import loadEmbedData from '../actions/loadEmbedData'
import updateHome from './updateHome'
import injectToBranches from './injectToBranches'
export default function changePage (page, continueSequence = []) {
return [
when(props`id`, branchId => !!branchId), {
false: [],
true: [
set(state`app.currentBranch`, props`id`),
],
},
set(state`app.currentPage`, page),
when(state`app.dataLoaded`), {
true: continueSequence,
false: [
set(state`app.loadingData`, true),
sequence('Load data and coords', [
loadEmbedData, {
true: [],
false: [
httpGet('/help-centre/branch-locator', {}),
],
},
set(state`app.branches`, props`result.branches`),
...injectToBranches,
set(state`app.footer`, props`result.footer`),
set(state`app.header`, props`result.header`),
set(state`app.theme_uri`, props`result.theme_uri`),
...updateHome,
]),
set(state`app.loadingData`, false),
set(state`app.dataLoaded`, true),
continueSequence,
],
},
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment