Skip to content

Instantly share code, notes, and snippets.

@ntilwalli
Last active March 8, 2016 20:23
Show Gist options
  • Save ntilwalli/1cb91f67e51f70356283 to your computer and use it in GitHub Desktop.
Save ntilwalli/1cb91f67e51f70356283 to your computer and use it in GitHub Desktop.
Sketch of possible nested requests approach in CycleJS
function modifications(actions, fromHTTP$) {
  const secondaryResponsesMod$ = fromHTTP$
    .map(resp => function (state) {
      // compare response with the keys in state.get('secondaryResponseContainer')
      // and fill the value in appropriately, if all expected responses have come in, set inFlight to false
      return state.set(`inFlight`, false)
    })
}

function generateSecondaryRequests (response) {
  // Generate the secondary requests and return them
}

function generateSecondaryResponsesContainer (requests) {
  // return an object that extracts the URLs associated with the
  // requests and set them as the keys with initially null,
  // values will be set when responses come back.  Keys will
  // be used at that time to match/bucket appropriately.
}

function model(actions, fromHTTP$) {
  const mod$ = modifications(actions, fromHTTP$)
  const state$ = actions.primaryResponse$
    .startWith([])
    .map(x => {
      const secondaryRequests = generateSecondaryRequests(x)
      const secondaryResponsesContainer = generateSecondaryResponsesContainer(secondaryRequests)
      return Immutable.Map({
        primaryResponse: x,
        secondaryRequests,
        secondaryResponsesContainer,
        inFlight: true
`     })
    })
    .flatMapLatest(state => mod$.startWith(state).scan((acc, mod) => mod(acc)))

  return state$
}

// If inFlight is true and secondaryResponsesContainer is fully empty send the secondaryRequests through to HTTP
// If inFlight is false, send through to view...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment