react-magnetic-di
Version:
Context driven dependency injection
22 lines (21 loc) • 750 B
JavaScript
import { KEY } from './constants';
var hasWarned = false;
export function warnOnce(message) {
if (!hasWarned) {
// eslint-disable-next-line no-console
console.error('Warning:', message);
hasWarned = true;
}
}
export function getDisplayName(Comp) {
var wrapper = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var name = Comp.displayName || Comp.name;
return !name || !wrapper ? name : "".concat(wrapper, "(").concat(name, ")");
}
export function injectable(from, implementation) {
implementation.displayName = getDisplayName(implementation) || getDisplayName(from, 'di');
implementation[KEY] = from;
return implementation;
}
/** @deprecated use injectable instead */
export var mock = injectable;