UNPKG

react_ujs

Version:

Rails UJS for the react-rails gem

23 lines (18 loc) 673 B
// Assume className is simple and can be found at top-level (window). // Fallback to eval to handle cases like 'My.React.ComponentName'. // Also, try to gracefully import Babel 6 style default exports var topLevel = typeof window === "undefined" ? this : window; module.exports = function(className) { var constructor; // Try to access the class globally first constructor = topLevel[className]; // If that didn't work, try eval if (!constructor) { constructor = eval(className); } // Lastly, if there is a default attribute try that if (constructor && constructor['default']) { constructor = constructor['default']; } return constructor; }