UNPKG

react_ujs

Version:

Rails UJS for the react-rails gem

26 lines (24 loc) 688 B
// Make a function which: // - First tries to require the name // - Then falls back to global lookup var fromGlobal = require("./fromGlobal") var fromRequireContext = require("./fromRequireContext") module.exports = function(reqctx) { var fromCtx = fromRequireContext(reqctx) return function(className) { var component; try { // `require` will raise an error if this className isn't found: component = fromCtx(className) } catch (firstErr) { // fallback to global: try { component = fromGlobal(className) } catch (secondErr) { console.error(firstErr) console.error(secondErr) } } return component } }