src/resolveRecursive.js
function getDataFromTree(rootElement, rootContext, fetchRoot, mergeProps, isTopLevel){

  //console.log(`Now searching element (${rootElement.type.name || rootElement.type.displayName}):`, rootElement);

  // Get array of queries (fetchData promises) from tree
  // This will traverse down recursively looking for fetchData() methods
  let queries = getQueriesFromTree(rootElement, rootContext, fetchRoot, mergeProps);

  // No queries found. We're done!
  if (!queries.length) {
    return Promise.resolve();
  }

  // We've traversed down as far as possible in thecurrent tree branch ...
  // Wait on each query that we found, re-rendering the subtree when it's done.
  const mappedQueries = queries.map(({ query, element, context }) =>  {
    return query.then((newProps) => {
      const displayName = element.type.displayName;

      if (!displayName){
        // TODO: Use Promise.reject and catch()
        throw new Error('[React Component Data] When resolving component data recursively each component must have a displayName set.');
      }

      // Add to finalData array that will be returned
      finalData[displayName] = newProps;
      // Traverse children
      // Component will use newProps returned by the query so we can find any children it might have as a result
      return getDataFromTree(element, context, false, newProps);
    })
  });

  return Promise.all(mappedQueries).then((values) => {
    // Only return final data at top level
    // Not inside recursive getDataFromTree calls
    if (isTopLevel){
      return finalData;
    }
  });
}
function getDataFromTree(rootElement, rootContext, fetchRoot, mergeProps, isTopLevel){

  //console.log(`Now searching element (${rootElement.type.name || rootElement.type.displayName}):`, rootElement);

  // Get array of queries (fetchData promises) from tree
  // This will traverse down recursively looking for fetchData() methods
  let queries = getQueriesFromTree(rootElement, rootContext, fetchRoot, mergeProps);

  // No queries found. We're done!
  if (!queries.length) {
    return Promise.resolve();
  }

  // We've traversed down as far as possible in thecurrent tree branch ...
  // Wait on each query that we found, re-rendering the subtree when it's done.
  const mappedQueries = queries.map(({ query, element, context }) =>  {
    return query.then((newProps) => {
      const displayName = element.type.displayName;

      if (!displayName){
        // TODO: Use Promise.reject and catch()
        throw new Error('[React Component Data] When resolving component data recursively each component must have a displayName set.');
      }

      // Add to finalData array that will be returned
      finalData[displayName] = newProps;
      // Traverse children
      // Component will use newProps returned by the query so we can find any children it might have as a result
      return getDataFromTree(element, context, false, newProps);
    })
  });

  return Promise.all(mappedQueries).then((values) => {
    // Only return final data at top level
    // Not inside recursive getDataFromTree calls
    if (isTopLevel){
      return finalData;
    }
  });
}
function getDataFromTree ( rootElement , rootContext , fetchRoot , mergeProps , isTopLevel ) { //console.log(`Now searching element (${rootElement.type.name || rootElement.type.displayName}):`, rootElement); // Get array of queries (fetchData promises) from tree // This will traverse down recursively looking for fetchData() methods let queries = getQueriesFromTree ( rootElement , rootContext , fetchRoot , mergeProps ) ; // No queries found. We're done! if ( ! queries . length ) { return Promise . resolve ( ) ; } // We've traversed down as far as possible in thecurrent tree branch ... // Wait on each query that we found, re-rendering the subtree when it's done. const mappedQueries = queries . map ( ( { query , element , context } ) => { return query . then ( ( newProps ) => { const displayName = element . type . displayName ; if ( ! displayName ) { // TODO: Use Promise.reject and catch() throw new Error ( '[React Component Data] When resolving component data recursively each component must have a displayName set.' ) ; } // Add to finalData array that will be returned finalData [ displayName ] = newProps ; // Traverse children // Component will use newProps returned by the query so we can find any children it might have as a result return getDataFromTree ( element , context , false , newProps ) ; } ) } ) ; return Promise . all ( mappedQueries ) . then ( ( values ) => { // Only return final data at top level // Not inside recursive getDataFromTree calls if ( isTopLevel ) { return finalData ; } } ) ; }
XXX component Cache
XXX component Cache