async function hydrate(groups) {
  let queue = Object.entries(groups).reduce((arr, [groupName, group]) => arr.concat(Object.entries(group).map(([type, block]) => ({groupName, group, type, block}))), [])
  function sort() { // Sort based on distance to the top of the screen
    queue.sort((a, b) => Math.abs(b.block.container.getBoundingClientRect().top) - Math.abs(a.block.container.getBoundingClientRect().top))
  }
  sort()

  for (let next = queue.pop(); next; next = queue.pop()) {
    const {groupName, type, block} = next

    // Hydrate
    hydrateEditor(type, block)
    hydrateButtons(groups, groupName, type, block)

    // Occasionally re-sort the queue in case the user scrolls.
    if (!(queue.length % HYDRATION_QUEUE_SORT_PERIOD)) {
      sort()
    }

    // Don't freeze the browser :)
    await delay(1)
  }
}
// Hydrate the all the blocks as applicable
Hydrate the all the blocks as applicable
Hydrate the all the blocks as applicable
async function hydrate(groups) {
  let queue = Object.entries(groups).reduce((arr, [groupName, group]) => arr.concat(Object.entries(group).map(([type, block]) => ({groupName, group, type, block}))), [])
  function sort() { 
    queue.sort((a, b) => Math.abs(b.block.container.getBoundingClientRect().top) - Math.abs(a.block.container.getBoundingClientRect().top))
  }
  sort()
  for (let next = queue.pop(); next; next = queue.pop()) {
    const {groupName, type, block} = next
    hydrateEditor(type, block)
    hydrateButtons(groups, groupName, type, block)
    if (!(queue.length % HYDRATION_QUEUE_SORT_PERIOD)) {
      sort()
    }
    await delay(1)
  }
}
async function hydrate ( groups ) { let queue = Object . entries ( groups ) . reduce ( ( arr , [ groupName , group ] ) => arr . concat ( Object . entries ( group ) . map ( ( [ type , block ] ) => ( { groupName , group , type , block } ) ) ) , [ ] ) function sort ( ) { queue . sort ( ( a , b ) => Math . abs ( b . block . container . getBoundingClientRect ( ) . top ) - Math . abs ( a . block . container . getBoundingClientRect ( ) . top ) ) } sort ( ) for ( let next = queue . pop ( ) ; next ; next = queue . pop ( ) ) { const { groupName , type , block } = next hydrateEditor ( type , block ) hydrateButtons ( groups , groupName , type , block ) if ( ! ( queue . length % HYDRATION_QUEUE_SORT_PERIOD ) ) { sort ( ) } await delay ( 1 ) } }
Hydrate the all the blocks as applicable
Hydrate the all the blocks as applicable
// Sort based on distance to the top of the screen // Hydrate // Occasionally re-sort the queue in case the user scrolls. // Don't freeze the browser :)