power-di
Version:
A lightweight Dependency Injection library. Using es6 and other features, remove unnecessary concepts, easy and convenient to use.
81 lines • 3.75 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.iocConsumer = void 0;
var React = require("react");
var context_1 = require("./context");
var BaseComponent_1 = require("./BaseComponent");
function iocConsumer(opt) {
if (opt === void 0) { opt = {}; }
opt = Object.assign({}, opt);
return function (Comp) {
var _a, _b;
var NewComp = opt.manualExtendsBaseClass ? Comp : (0, BaseComponent_1.createConsumerComponent)(Comp);
return opt.pureComponent
? (_a = /** @class */ (function (_super) {
__extends(IoCPureComponent, _super);
function IoCPureComponent() {
return _super !== null && _super.apply(this, arguments) || this;
}
IoCPureComponent.prototype.render = function () {
var _this = this;
return (React.createElement(context_1.Context.Consumer, null, function (ctx) {
var _a;
return (React.createElement(NewComp, __assign({}, Object.assign({}, _this.props, (_a = {},
_a[context_1.ContextSymbol] = ctx,
_a)))));
}));
};
return IoCPureComponent;
}(React.PureComponent)),
_a.displayName = "IoCComponent(".concat(getDisplayName(Comp), ")"),
_a) : (_b = /** @class */ (function (_super) {
__extends(IoCComponent, _super);
function IoCComponent() {
return _super !== null && _super.apply(this, arguments) || this;
}
IoCComponent.prototype.render = function () {
var _this = this;
return (React.createElement(context_1.Context.Consumer, null, function (ctx) {
var _a;
return (React.createElement(NewComp, __assign({}, Object.assign({}, _this.props, (_a = {},
_a[context_1.ContextSymbol] = ctx,
_a)))));
}));
};
return IoCComponent;
}(React.Component)),
_b.displayName = "IoCComponent(".concat(getDisplayName(Comp), ")"),
_b);
};
}
exports.iocConsumer = iocConsumer;
function getDisplayName(WrappedComponent) {
return WrappedComponent.displayName || WrappedComponent.name;
}
//# sourceMappingURL=IocConsumer.js.map