packages/devtools-reps/src/reps/rep-utils.js
function getGripPreviewItems(grip) {
  if (!grip) {
    return [];
  }

  // Promise resolved value Grip
  if (grip.promiseState && grip.promiseState.value) {
    return [grip.promiseState.value];
  }

  // Array Grip
  if (grip.preview && grip.preview.items) {
    return grip.preview.items;
  }

  // Node Grip
  if (grip.preview && grip.preview.childNodes) {
    return grip.preview.childNodes;
  }

  // Set or Map Grip
  if (grip.preview && grip.preview.entries) {
    return grip.preview.entries.reduce((res, entry) => res.concat(entry), []);
  }

  // Event Grip
  if (grip.preview && grip.preview.target) {
    const keys = Object.keys(grip.preview.properties);
    const values = Object.values(grip.preview.properties);
    return [grip.preview.target, ...keys, ...values];
  }

  // RegEx Grip
  if (grip.displayString) {
    return [grip.displayString];
  }

  // Generic Grip
  if (grip.preview && grip.preview.ownProperties) {
    let propertiesValues = Object.values(grip.preview.ownProperties).map(
      property => property.value || property
    );

    const propertyKeys = Object.keys(grip.preview.ownProperties);
    propertiesValues = propertiesValues.concat(propertyKeys);

    // ArrayBuffer Grip
    if (grip.preview.safeGetterValues) {
      propertiesValues = propertiesValues.concat(
        Object.values(grip.preview.safeGetterValues).map(
          property => property.getterValue || property
        )
      );
    }

    return propertiesValues;
  }

  return [];
}
function getGripPreviewItems(grip) {
  if (!grip) {
    return [];
  }

  // Promise resolved value Grip
  if (grip.promiseState && grip.promiseState.value) {
    return [grip.promiseState.value];
  }

  // Array Grip
  if (grip.preview && grip.preview.items) {
    return grip.preview.items;
  }

  // Node Grip
  if (grip.preview && grip.preview.childNodes) {
    return grip.preview.childNodes;
  }

  // Set or Map Grip
  if (grip.preview && grip.preview.entries) {
    return grip.preview.entries.reduce((res, entry) => res.concat(entry), []);
  }

  // Event Grip
  if (grip.preview && grip.preview.target) {
    const keys = Object.keys(grip.preview.properties);
    const values = Object.values(grip.preview.properties);
    return [grip.preview.target, ...keys, ...values];
  }

  // RegEx Grip
  if (grip.displayString) {
    return [grip.displayString];
  }

  // Generic Grip
  if (grip.preview && grip.preview.ownProperties) {
    let propertiesValues = Object.values(grip.preview.ownProperties).map(
      property => property.value || property
    );

    const propertyKeys = Object.keys(grip.preview.ownProperties);
    propertiesValues = propertiesValues.concat(propertyKeys);

    // ArrayBuffer Grip
    if (grip.preview.safeGetterValues) {
      propertiesValues = propertiesValues.concat(
        Object.values(grip.preview.safeGetterValues).map(
          property => property.getterValue || property
        )
      );
    }

    return propertiesValues;
  }

  return [];
}
function getGripPreviewItems ( grip ) { if ( ! grip ) { return [ ] ; } // Promise resolved value Grip if ( grip . promiseState && grip . promiseState . value ) { return [ grip . promiseState . value ] ; } // Array Grip if ( grip . preview && grip . preview . items ) { return grip . preview . items ; } // Node Grip if ( grip . preview && grip . preview . childNodes ) { return grip . preview . childNodes ; } // Set or Map Grip if ( grip . preview && grip . preview . entries ) { return grip . preview . entries . reduce ( ( res , entry ) => res . concat ( entry ) , [ ] ) ; } // Event Grip if ( grip . preview && grip . preview . target ) { const keys = Object . keys ( grip . preview . properties ) ; const values = Object . values ( grip . preview . properties ) ; return [ grip . preview . target , ... keys , ... values ] ; } // RegEx Grip if ( grip . displayString ) { return [ grip . displayString ] ; } // Generic Grip if ( grip . preview && grip . preview . ownProperties ) { let propertiesValues = Object . values ( grip . preview . ownProperties ) . map ( property => property . value || property ) ; const propertyKeys = Object . keys ( grip . preview . ownProperties ) ; propertiesValues = propertiesValues . concat ( propertyKeys ) ; // ArrayBuffer Grip if ( grip . preview . safeGetterValues ) { propertiesValues = propertiesValues . concat ( Object . values ( grip . preview . safeGetterValues ) . map ( property => property . getterValue || property ) ) ; } return propertiesValues ; } return [ ] ; }
Get preview items from a Grip.

@param {Object} Grip from which we want the preview items
@return {Array} Array of the preview items of the grip, or an empty array
if the grip does not have preview items
Get preview items from a Grip .