UNPKG

react-apollo

Version:
59 lines 2.71 kB
var __extends = (this && this.__extends) || (function () { var 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 function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__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; }; import * as React from 'react'; import ApolloConsumer from './ApolloConsumer'; var invariant = require('invariant'); var hoistNonReactStatics = require('hoist-non-react-statics'); function getDisplayName(WrappedComponent) { return WrappedComponent.displayName || WrappedComponent.name || 'Component'; } export default function withApollo(WrappedComponent, operationOptions) { if (operationOptions === void 0) { operationOptions = {}; } var withDisplayName = "withApollo(" + getDisplayName(WrappedComponent) + ")"; var WithApollo = (function (_super) { __extends(WithApollo, _super); function WithApollo(props) { var _this = _super.call(this, props) || this; _this.setWrappedInstance = _this.setWrappedInstance.bind(_this); return _this; } WithApollo.prototype.getWrappedInstance = function () { invariant(operationOptions.withRef, "To access the wrapped instance, you need to specify " + "{ withRef: true } in the options"); return this.wrappedInstance; }; WithApollo.prototype.setWrappedInstance = function (ref) { this.wrappedInstance = ref; }; WithApollo.prototype.render = function () { var _this = this; return (React.createElement(ApolloConsumer, null, function (client) { var props = Object.assign({}, _this.props, { client: client, ref: operationOptions.withRef ? _this.setWrappedInstance : undefined, }); return React.createElement(WrappedComponent, __assign({}, props)); })); }; WithApollo.displayName = withDisplayName; WithApollo.WrappedComponent = WrappedComponent; return WithApollo; }(React.Component)); return hoistNonReactStatics(WithApollo, WrappedComponent, {}); } //# sourceMappingURL=withApollo.js.map