@dorgtech/daocomponents
Version:
Componentizing [DAOstack's client library](https://github.com/daostack/client), enabling easier React application integration. The hope is to be able to turn any app into a DAO enabled dApp by adding ~2 components.
92 lines • 4.52 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 (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var LoadingView_1 = require("./LoadingView");
var ContextFeed = /** @class */ (function (_super) {
__extends(ContextFeed, _super);
function ContextFeed(props) {
return _super.call(this, props) || this;
}
ContextFeed.prototype.render = function () {
var _a = this.props, children = _a.children, _consumers = _a._consumers, _logs = _a._logs;
if (!_consumers || !_logs) {
throw Error("Error: ContextFeed missing context consumer(s).");
}
if (!children) {
throw Error("Error: A ContextFeed requires a child component.");
}
if (typeof children === "function") {
// TODO: make sure it's a function w/ the correct argument types
// var args: ArgumentTypes<typeof children> = ["foo", "foo"];
var length_1 = _consumers.length;
var RelayValues_1 = function (index, values) {
if (values === void 0) { values = []; }
if (index < length_1) {
// If we are still iterating through _consumers
var Consumer = _consumers[index];
// render the context consumers, and pass the
// value to this function recursively
return (React.createElement(Consumer, null, function (value) { return (RelayValues_1(index + 1, values.concat([value]))); }));
}
else {
// We've recursed through all consumers. Now let's
// check for undefined values and give logging information
// for why they're undefined.
var nullIndex = values.indexOf(undefined);
// If we have a value that is still undefined
if (nullIndex > -1) {
// Get its logs and pass them to the LoadingView component
var Logs = _logs[nullIndex];
// TODO: This is required because Protocol's don't have logs. Need to add this, or just make Protocol's components...
if (Logs === undefined) {
return React.createElement("div", null, "Loading...");
}
return (React.createElement(Logs, null, function (logs) { return React.createElement(LoadingView_1.default, { logs: logs }); }));
}
else {
return children.apply(void 0, values);
}
}
};
return RelayValues_1(0);
}
// In this case, the child or children are components,
// so we'll inject them with our _consumers
if (children["length"]) {
var childrenArray = children;
var newChildren = new Array();
for (var _i = 0, childrenArray_1 = childrenArray; _i < childrenArray_1.length; _i++) {
var child = childrenArray_1[_i];
newChildren.push(React.cloneElement(child, {
_consumers: _consumers,
_logs: _logs
}));
}
return (React.createElement(React.Fragment, null, newChildren));
}
else {
return React.cloneElement(children, {
_consumers: _consumers,
_logs: _logs
});
}
};
return ContextFeed;
}(React.Component));
exports.CreateContextFeed = function (consumer, logs) { return (function (props) { return (React.createElement(ContextFeed, { _consumers: props._consumers ? props._consumers.concat([consumer]) :
[consumer], _logs: props._logs ? props._logs.concat([logs]) :
[logs], children: props.children })); }); };
//# sourceMappingURL=ContextFeed.js.map