@talend/react-cmf
Version:
A framework built on top of best react libraries
64 lines (63 loc) • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CmfRegisteredSaga = void 0;
exports.CmfRegisteredSagaComponent = CmfRegisteredSagaComponent;
var _react = require("react");
var _reactRedux = require("react-redux");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _utils = require("@talend/utils");
var _saga = require("../../actions/saga");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function CmfRegisteredSagaComponent({
sagaId,
startSaga,
stopSaga,
sagaAttributes,
componentId = 'default',
children = null
}) {
const id = (0, _react.useMemo)(_utils.randomUUID, []);
// If we pass the sagaId, we use the cmf registry
(0, _react.useEffect)(() => {
if (sagaId) {
startSaga({
type: 'DID_MOUNT',
componentId: id
}, {
saga: sagaId,
componentId,
...sagaAttributes
});
}
return () => {
if (sagaId) {
stopSaga({
type: 'WILL_UNMOUNT',
componentId: id
}, {
saga: sagaId,
componentId
});
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return children;
}
CmfRegisteredSagaComponent.propTypes = {
sagaId: _propTypes.default.string.isRequired,
startSaga: _propTypes.default.func.isRequired,
stopSaga: _propTypes.default.func.isRequired,
sagaAttributes: _propTypes.default.any,
componentId: _propTypes.default.string,
children: _propTypes.default.node
};
CmfRegisteredSagaComponent.displayName = 'CmfRegisteredSagaComponent';
const mapDispatchToProps = dispatch => ({
startSaga: (event, properties) => dispatch((0, _saga.start)(event, properties)),
stopSaga: (event, properties) => dispatch((0, _saga.stop)(event, properties))
});
const CmfRegisteredSaga = exports.CmfRegisteredSaga = (0, _reactRedux.connect)(null, mapDispatchToProps)(CmfRegisteredSagaComponent);
//# sourceMappingURL=CmfRegisteredSaga.component.js.map