src/tinier.js
function singleOrAll (modelNode, address, minTreeAr) {
  const getMin = indices => {
    if (indices.length === 0) {
      // If all elements in the array are null, return null.
      return null
    } else if (nonNullIndices.signals.length === 1) {
      // If there is a single value, return that tree, with an updated address.
      return {
        minSignals: {
          diff: minTreeAr.map(a => a.minSignals.diff),
          address,
          modelNode,
        },
        minUpdate: {
          diff: minTreeAr.map(a => a.minUpdate.diff),
          address,
          modelNode,
        },
      }
    } else {
      // Otherwise, return full trees from this level.
      return {
        minSignals: {
          diff: minTreeAr.map(a => a.minSignals.diff),
          address,
          modelNode,
        },
        minUpdate: {
          diff: minTreeAr.map(a => a.minUpdate.diff),
          address,
          modelNode,
        },
      }
    }
  }
  // Get the indices where the signal and update trees are not null.
  const nonNullIndices = minTreeAr.reduce((accum, val, i) => {
    return {
      signals: val.minSignals !== null ? [ ...accum.signals, i ]: accum.signals,
      update: val.minUpdate !== null ? [ ...accum.update, i ]: accum.update,
    }
  }, { signals: [], update: [] })
  // For each set of indices, test the diffs with these tests to get a minimum
  // tree.
  const minSignals = getMin(nonNullIndices.signals)
  const minUpdate = getMin(nonNullIndices.update)
  return { minSignals, minUpdate }
}
function singleOrAll (modelNode, address, minTreeAr) {
  const getMin = indices => {
    if (indices.length === 0) {
      // If all elements in the array are null, return null.
      return null
    } else if (nonNullIndices.signals.length === 1) {
      // If there is a single value, return that tree, with an updated address.
      return {
        minSignals: {
          diff: minTreeAr.map(a => a.minSignals.diff),
          address,
          modelNode,
        },
        minUpdate: {
          diff: minTreeAr.map(a => a.minUpdate.diff),
          address,
          modelNode,
        },
      }
    } else {
      // Otherwise, return full trees from this level.
      return {
        minSignals: {
          diff: minTreeAr.map(a => a.minSignals.diff),
          address,
          modelNode,
        },
        minUpdate: {
          diff: minTreeAr.map(a => a.minUpdate.diff),
          address,
          modelNode,
        },
      }
    }
  }
  // Get the indices where the signal and update trees are not null.
  const nonNullIndices = minTreeAr.reduce((accum, val, i) => {
    return {
      signals: val.minSignals !== null ? [ ...accum.signals, i ]: accum.signals,
      update: val.minUpdate !== null ? [ ...accum.update, i ]: accum.update,
    }
  }, { signals: [], update: [] })
  // For each set of indices, test the diffs with these tests to get a minimum
  // tree.
  const minSignals = getMin(nonNullIndices.signals)
  const minUpdate = getMin(nonNullIndices.update)
  return { minSignals, minUpdate }
}
function singleOrAll ( modelNode , address , minTreeAr ) { const getMin = indices => { if ( indices . length === 0 ) { // If all elements in the array are null, return null. return null } else if ( nonNullIndices . signals . length === 1 ) { // If there is a single value, return that tree, with an updated address. return { minSignals : { diff : minTreeAr . map ( a => a . minSignals . diff ) , address , modelNode , } , minUpdate : { diff : minTreeAr . map ( a => a . minUpdate . diff ) , address , modelNode , } , } } else { // Otherwise, return full trees from this level. return { minSignals : { diff : minTreeAr . map ( a => a . minSignals . diff ) , address , modelNode , } , minUpdate : { diff : minTreeAr . map ( a => a . minUpdate . diff ) , address , modelNode , } , } } } // Get the indices where the signal and update trees are not null. const nonNullIndices = minTreeAr . reduce ( ( accum , val , i ) => { return { signals : val . minSignals !== null ? [ ... accum . signals , i ] : accum . signals , update : val . minUpdate !== null ? [ ... accum . update , i ] : accum . update , } } , { signals : [ ] , update : [ ] } ) // For each set of indices, test the diffs with these tests to get a minimum // tree. const minSignals = getMin ( nonNullIndices . signals ) const minUpdate = getMin ( nonNullIndices . update ) return { minSignals , minUpdate } }
For an array of minSignals and minUpdate trees, return the minimal trees that
represent the whole array.
For an array of minSignals and minUpdate trees return the minimal trees that represent the whole array .