refun
Version:
A collection of React Hook-enabled functions that compose harmoniously with each other. Similar to `recompose`, but:
29 lines (22 loc) • 766 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mapHandlersFactory = void 0;
var _react = require("react");
var _tsfn = require("tsfn");
const mapHandlersFactory = getHandlers => props => {
const actualHandlers = (0, _react.useRef)(_tsfn.EMPTY_OBJECT);
const propsRef = (0, _react.useRef)(props);
propsRef.current = props;
if (actualHandlers.current === _tsfn.EMPTY_OBJECT) {
const handlers = getHandlers(props);
actualHandlers.current = (0, _tsfn.getObjectKeys)(handlers).reduce((result, key) => {
result[key] = (...args) => handlers[key](propsRef.current)(...args);
return result;
}, {});
}
return { ...props,
...actualHandlers.current
};
};
exports.mapHandlersFactory = mapHandlersFactory;