react-magnetic-di
Version:
Context driven dependency injection
25 lines (21 loc) • 964 B
JavaScript
import { PACKAGE_NAME } from './constants';
import { Context } from './context';
import { warnOnce, mock } from './utils';
function di(deps, target) {
// check if babel plugin has been added
if (Array.isArray(deps)) {
// Read context and grab all the dependencies override
// from all Providers in the tree
var _ref = Context._currentValue || {},
_ref$getDependencies = _ref.getDependencies,
getDependencies = _ref$getDependencies === void 0 ? function (v) {
return v;
} : _ref$getDependencies;
return getDependencies(deps, target);
} else {
warnOnce("Seems like you are using ".concat(PACKAGE_NAME, " without Babel plugin. ") + "Please add '".concat(PACKAGE_NAME, "/babel-plugin' to your Babel config ") + "or import from '".concat(PACKAGE_NAME, "/macro' if your are using 'babel-plugin-macros'. ") + 'di(...) run as a no-op.');
}
}
/** @deprecated use injectable instead */
di.mock = mock;
export { di };