src/js/tabWindow.js
function getOpenTabInfo(tabItems, openTabs) {
  const chromeOpenTabItems = Immutable.Seq(openTabs.map(makeOpenTabItem));

  // console.log("getOpenTabInfo: openTabs: ", openTabs);
  // console.log("getOpenTabInfo: chromeOpenTabItems: " + JSON.stringify(chromeOpenTabItems,null,4));
  const openUrlMap = Immutable.Map(chromeOpenTabItems.groupBy((ti) => ti.url));

  // console.log("getOpenTabInfo: openUrlMap: ", openUrlMap.toJS());

  // Now we need to do two things:
  // 1. augment chromeOpenTabItems with bookmark Ids / saved state (if it exists)
  // 2. figure out which savedTabItems are not in openTabs
  const savedItems = tabItems.filter((ti) => ti.saved);

  // Restore the saved items to their base state (no open tab info), since we
  // only want to pick up open tab info from what was passed in in openTabs
  const baseSavedItems = savedItems.map(resetSavedItem);

  // The entries in savedUrlMap *should* be singletons, but we'll use groupBy to
  // get a type-compatible Seq so that we can merge with openUrlMap using
  // mergeWith:
  const savedUrlMap = Immutable.Map(baseSavedItems.groupBy((ti) => ti.url));

  // console.log("getOpenTabInfo: savedUrlMap : " + savedUrlMap.toJS());

  function mergeTabItems(openItems, mergeSavedItems) {
    const savedItem = mergeSavedItems.get(0);
    return openItems.map((openItem) => openItem.set('saved', true)
                                        .set('savedBookmarkId', savedItem.savedBookmarkId)
                                        .set('savedBookmarkIndex', savedItem.savedBookmarkIndex)
                                        .set('savedTitle', savedItem.savedTitle));
  }

  const mergedMap = openUrlMap.mergeWith(mergeTabItems, savedUrlMap);

  // console.log("mergedMap: ", mergedMap.toJS());

  // console.log("getOpenTabInfo: mergedMap :" + JSON.stringify(mergedMap,null,4));

  // partition mergedMap into open and closed tabItems:
  const partitionedMap = mergedMap.toIndexedSeq().flatten(true).groupBy((ti) => ti.open);

  // console.log("partitionedMap: ", partitionedMap.toJS());

  return partitionedMap;
}
function getOpenTabInfo(tabItems, openTabs) {
  const chromeOpenTabItems = Immutable.Seq(openTabs.map(makeOpenTabItem));

  // console.log("getOpenTabInfo: openTabs: ", openTabs);
  // console.log("getOpenTabInfo: chromeOpenTabItems: " + JSON.stringify(chromeOpenTabItems,null,4));
  const openUrlMap = Immutable.Map(chromeOpenTabItems.groupBy((ti) => ti.url));

  // console.log("getOpenTabInfo: openUrlMap: ", openUrlMap.toJS());

  // Now we need to do two things:
  // 1. augment chromeOpenTabItems with bookmark Ids / saved state (if it exists)
  // 2. figure out which savedTabItems are not in openTabs
  const savedItems = tabItems.filter((ti) => ti.saved);

  // Restore the saved items to their base state (no open tab info), since we
  // only want to pick up open tab info from what was passed in in openTabs
  const baseSavedItems = savedItems.map(resetSavedItem);

  // The entries in savedUrlMap *should* be singletons, but we'll use groupBy to
  // get a type-compatible Seq so that we can merge with openUrlMap using
  // mergeWith:
  const savedUrlMap = Immutable.Map(baseSavedItems.groupBy((ti) => ti.url));

  // console.log("getOpenTabInfo: savedUrlMap : " + savedUrlMap.toJS());

  function mergeTabItems(openItems, mergeSavedItems) {
    const savedItem = mergeSavedItems.get(0);
    return openItems.map((openItem) => openItem.set('saved', true)
                                        .set('savedBookmarkId', savedItem.savedBookmarkId)
                                        .set('savedBookmarkIndex', savedItem.savedBookmarkIndex)
                                        .set('savedTitle', savedItem.savedTitle));
  }

  const mergedMap = openUrlMap.mergeWith(mergeTabItems, savedUrlMap);

  // console.log("mergedMap: ", mergedMap.toJS());

  // console.log("getOpenTabInfo: mergedMap :" + JSON.stringify(mergedMap,null,4));

  // partition mergedMap into open and closed tabItems:
  const partitionedMap = mergedMap.toIndexedSeq().flatten(true).groupBy((ti) => ti.open);

  // console.log("partitionedMap: ", partitionedMap.toJS());

  return partitionedMap;
}
function getOpenTabInfo ( tabItems , openTabs ) { const chromeOpenTabItems = Immutable . Seq ( openTabs . map ( makeOpenTabItem ) ) ; // console.log("getOpenTabInfo: openTabs: ", openTabs); // console.log("getOpenTabInfo: chromeOpenTabItems: " + JSON.stringify(chromeOpenTabItems,null,4)); const openUrlMap = Immutable . Map ( chromeOpenTabItems . groupBy ( ( ti ) => ti . url ) ) ; // console.log("getOpenTabInfo: openUrlMap: ", openUrlMap.toJS()); // Now we need to do two things: // 1. augment chromeOpenTabItems with bookmark Ids / saved state (if it exists) // 2. figure out which savedTabItems are not in openTabs const savedItems = tabItems . filter ( ( ti ) => ti . saved ) ; // Restore the saved items to their base state (no open tab info), since we // only want to pick up open tab info from what was passed in in openTabs const baseSavedItems = savedItems . map ( resetSavedItem ) ; // The entries in savedUrlMap *should* be singletons, but we'll use groupBy to // get a type-compatible Seq so that we can merge with openUrlMap using // mergeWith: const savedUrlMap = Immutable . Map ( baseSavedItems . groupBy ( ( ti ) => ti . url ) ) ; // console.log("getOpenTabInfo: savedUrlMap : " + savedUrlMap.toJS()); function mergeTabItems ( openItems , mergeSavedItems ) { const savedItem = mergeSavedItems . get ( 0 ) ; return openItems . map ( ( openItem ) => openItem . set ( 'saved' , true ) . set ( 'savedBookmarkId' , savedItem . savedBookmarkId ) . set ( 'savedBookmarkIndex' , savedItem . savedBookmarkIndex ) . set ( 'savedTitle' , savedItem . savedTitle ) ) ; } const mergedMap = openUrlMap . mergeWith ( mergeTabItems , savedUrlMap ) ; // console.log("mergedMap: ", mergedMap.toJS()); // console.log("getOpenTabInfo: mergedMap :" + JSON.stringify(mergedMap,null,4)); // partition mergedMap into open and closed tabItems: const partitionedMap = mergedMap . toIndexedSeq ( ) . flatten ( true ) . groupBy ( ( ti ) => ti . open ) ; // console.log("partitionedMap: ", partitionedMap.toJS()); return partitionedMap ; }
Gather open tab items and a set of non-open saved tabItems from the given
open tabs and tab items based on URL matching, without regard to
tab ordering.  Auxiliary helper function for mergeOpenTabs.
Gather open tab items and a set of non - open saved tabItems from the given open tabs and tab items based on URL matching without regard to tab ordering . Auxiliary helper function for mergeOpenTabs .