@appbuckets/react-ui-smart-components
Version:
UI Extended Components that work with @appbuckets/react-client and @appbuckets/react-ui
67 lines (61 loc) • 1.59 kB
JavaScript
;
var _tslib = require('../../_virtual/_tslib.js');
var React = require('react');
var QuerySuspendedComponent = require('../QuerySuspendedComponent.js');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(
n,
k,
d.get
? d
: {
enumerable: true,
get: function () {
return e[k];
},
}
);
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/ _interopNamespace(React);
/* --------
* HOC Definition
* -------- */
function asSuspendedComponent(Component, useQuery, queryArgs, config) {
return function SuspendedWithHOC(props) {
// ----
// Get Query Args
// ----
var useQueryArgs =
typeof queryArgs === 'function' ? queryArgs(props) : queryArgs;
// ----
// Execute Query
// ----
var useQueryResult = useQuery.apply(
void 0,
_tslib.__spreadArray([], _tslib.__read(useQueryArgs), false)
);
// ----
// Component Render
// ----
return React__namespace.createElement(
QuerySuspendedComponent,
_tslib.__assign(_tslib.__assign({}, config), {
Component: Component,
query: useQueryResult,
innerProps: props,
})
);
};
}
module.exports = asSuspendedComponent;