UNPKG

reshow-return

Version:

reshow-return (simple connect component with reshow-flux)

67 lines (64 loc) 2.2 kB
import _objectWithoutProperties from "reshow-runtime/es/helpers/objectWithoutProperties"; import _objectSpread from "reshow-runtime/es/helpers/objectSpread2"; var _excluded = ["children", "backfillProps"]; // @ts-check import { useConnect as useConn } from "reshow-flux"; import MemoReturn from "../organisms/MemoReturn.mjs"; import connectOptions from "../../connectOptions.mjs"; import * as React from "react"; /** * @typedef {object} GetReturnOptions * @property {string} [displayName] * @property {function} [useConnect] * @property {string[]} [cleanProps] * @property {object} [options] */ /** * @template StateType * @template ActionType * * @typedef {object} ReturnProps * @property {import("reshow-flux-base").StoreObject<StateType, ActionType>} store * @property {import("../../connectOptions").InitStatesType} [initStates] * @property {{[key: string]: string[]}} [pathStates] * @property {import("react").ReactNode[] | import("react").ReactNode} [children] * @property {boolean} [backfillProps] */ /** * @param {GetReturnOptions} props * @returns {React.ElementType} */ import { jsx as _jsx } from "react/jsx-runtime"; var getReturn = function getReturn(_temp) { var { displayName = "Return", useConnect, cleanProps, options } = _temp === void 0 ? {} : _temp; useConnect = useConnect || useConn(_objectSpread(_objectSpread({}, connectOptions), options)); /** * @template StateType * @template ActionType * * @param {ReturnProps<StateType, ActionType>} props */ var Return = function Return(props) { var { children, backfillProps } = props, otherProps = _objectWithoutProperties(props, _excluded); var state = /** @type function*/useConnect(props); var nextProps = backfillProps ? _objectSpread(_objectSpread({}, state), connectOptions.reset(otherProps, cleanProps)) : _objectSpread(_objectSpread({}, connectOptions.reset(otherProps, cleanProps)), state); return /*#__PURE__*/_jsx(MemoReturn, { props: nextProps, children: children }); }; Return.displayName = displayName; return Return; }; var Return = getReturn(); export default Return; export { getReturn };