function cacheKeyFromObject()

in packages-ext/recoil-devtools/src/utils/sankey/CV2_memoize.js [21:52]


function cacheKeyFromObject(object: mixed): mixed {
  if (typeof object === 'object' && object !== null && !isImmutable(object)) {
    const t0 = window.performance ? performance.now() : 0;
    // $FlowFixMe
    let answer: Immutable.Map<string, mixed> = Immutable.Map();
    // $FlowIssue[sketchy-null-mixed] #9606986 Symbols are not supported
    // $FlowIssue[incompatible-type] #9606986 Symbols are not supported
    if (object[KEY]) {
      answer = answer.set('key', object[KEY]);
    } else {
      Object.entries(object).forEach(([key, value]) => {
        answer =
          typeof value === 'object' &&
          value !== null &&
          // $FlowIssue[incompatible-type] #9606986 Symbols are not supported
          value[KEY] != null
            ? answer.set(key, value[KEY])
            : answer.set(key, Immutable.fromJS(value));
      });
    }
    const t1 = window.performance ? performance.now() : 0;
    if (__DEV__) {
      if (t1 - t0 > TIME_WARNING_THRESHOLD_MS) {
        // eslint-disable-next-line fb-www/no-console
        console.error('Spent', t1 - t0, 'milliseconds computing a cache key.');
      }
    }
    return answer;
  } else {
    return object;
  }
}