react-redux-isomorphic
Version:
Set of utilities for creating isomorphic applications using react-redux
61 lines (50 loc) • 1.75 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { LoadContextError } from './errors';
import { loadContextSuccess, loadContextError } from './actions';
var requestContext = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(isomorphicId, getContext, loadParams, dispatch) {
var context, error;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return getContext(loadParams);
case 3:
context = _context.sent;
_context.next = 9;
break;
case 6:
_context.prev = 6;
_context.t0 = _context["catch"](0);
error = _context.t0;
case 9:
if (error) {
_context.next = 12;
break;
}
dispatch(loadContextSuccess(isomorphicId, context));
return _context.abrupt("return");
case 12:
if (!(error instanceof LoadContextError)) {
_context.next = 15;
break;
}
dispatch(loadContextError(isomorphicId, error.error));
return _context.abrupt("return");
case 15:
throw error;
case 16:
case "end":
return _context.stop();
}
}
}, _callee, null, [[0, 6]]);
}));
return function requestContext(_x, _x2, _x3, _x4) {
return _ref.apply(this, arguments);
};
}();
export default requestContext;