JSFiddle - React, Tailwind, and code Playground

by cjblomqvist

HTML

Code for finding a specific fn within a big object

JavaScript

var lookup,
    max = 10;

lookup = function (obj, str, stack, i) {
  var stack = stack || '';
  var i = i || 1;

  i++;
  if(i > max) return false;

  var keys = Object.keys(obj),
      ret = false;

  if(typeof obj[str] !== 'undefined') return str;

  keys.every(function (key) {
    var key = key;

    if(_.isObject(obj[key]) && !_.isFunction(obj[key]) && !_.isArray(obj[key]) && key.indexOf('_instancesByReactRootID') < 0) {
      var newStack = stack + (stack !== '' ? '.' : '') + key;
console.log(newStack);
      var res = lookup(obj[key], str, stack + (stack !== '' ? '.' : '') + key, i);

      if(res === false) {
        return true;
      } else {
console.log('success??');
        ret = key + '.' + res;
        return false;
      }
    }

    return true;
  });

  return ret;
};