UNPKG

@talend/react-containers

Version:

Provide connected components aka containers for @talend/react-cmf based on @talend/react-components.

65 lines (62 loc) 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WAIT_FOR = exports.TAKE_ACTION = exports.SAGAS = exports.ACTION_CREATORS = void 0; exports.appLoaderSaga = appLoaderSaga; exports.handleStep = handleStep; exports.waitFor = waitFor; var _reactCmf = _interopRequireDefault(require("@talend/react-cmf")); var _effects = require("redux-saga/effects"); var _invariant = _interopRequireDefault(require("invariant")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const ACTION_CREATORS = exports.ACTION_CREATORS = 'actionCreators'; const SAGAS = exports.SAGAS = 'sagas'; const WAIT_FOR = exports.WAIT_FOR = 'waitFor'; const TAKE_ACTION = exports.TAKE_ACTION = 'takeAction'; /** * This function wait until a collection is here * @param {string} collectionName the name of the collection * @param {int} interval the interval to check again if the collection is there */ function* waitFor(collectionName, interval = 10) { // eslint-disable-next-line no-constant-condition while (true) { const collection = yield (0, _effects.select)(_reactCmf.default.selectors.collections.get, collectionName); if (collection !== undefined) { break; } yield (0, _effects.delay)(interval); } } /** * This function handle a specific step * @param {object} step a bootstrap step that could contain a actionCreator list or a waitList */ function* handleStep(step) { if (step[SAGAS]) { return yield (0, _effects.all)(step[SAGAS].map(saga => (0, _effects.call)(_reactCmf.default.sagas.get(saga)))); } if (step[ACTION_CREATORS]) { return yield (0, _effects.all)(step[ACTION_CREATORS].map(actionCreator => _reactCmf.default.sagas.putActionCreator(actionCreator))); } else if (step[WAIT_FOR]) { return yield (0, _effects.all)(step[WAIT_FOR].map(collectionName => (0, _effects.call)(waitFor, collectionName))); } else if (step[TAKE_ACTION]) { return yield (0, _effects.all)(step[TAKE_ACTION].map(actionName => (0, _effects.take)(actionName, actionName))); } return (0, _invariant.default)(process.env.NODE_ENV !== 'production', `Step object must have ${ACTION_CREATORS} or ${WAIT_FOR} attribute`); } /** * This saga load the actionCreator or wait on some steps * @param {object} props the saga props * @param {array} props.steps an array of steps to handle */ function* appLoaderSaga({ steps }) { // eslint-disable-next-line no-restricted-syntax for (const step of steps) { yield (0, _effects.call)(handleStep, step); } } //# sourceMappingURL=AppLoader.saga.js.map