@talend/react-cmf
Version:
A framework built on top of best react libraries
62 lines (59 loc) • 1.8 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.REQUEST_SETTINGS = exports.REQUEST_OK = exports.REQUEST_KO = void 0;
exports.errorWithSettings = errorWithSettings;
exports.fetchSettings = fetchSettings;
exports.receiveSettings = receiveSettings;
exports.requestSettings = requestSettings;
var _http = _interopRequireDefault(require("./http"));
var _constant = _interopRequireDefault(require("../constant"));
var _lodash = require("lodash");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* @module react-cmf/lib/actions/settingsActions
*/
// keep backward compatibility
const {
REQUEST_OK,
REQUEST_KO,
REQUEST_SETTINGS
} = _constant.default;
exports.REQUEST_SETTINGS = REQUEST_SETTINGS;
exports.REQUEST_KO = REQUEST_KO;
exports.REQUEST_OK = REQUEST_OK;
function requestSettings() {
return {
type: _constant.default.REQUEST_SETTINGS
};
}
function receiveSettings(json) {
return {
type: _constant.default.REQUEST_OK,
settings: json,
receivedAt: Date.now()
};
}
function errorWithSettings(error) {
return {
type: _constant.default.REQUEST_KO,
error: {
message: (0, _lodash.get)(error, 'message'),
stack: (0, _lodash.get)(error, 'stack')
}
};
}
/**
* get the settings on the server and dispatch the corresponding actions
* this should be executed during the bootstrap of the App.
* @param path Path of the settings.json file to fetch. Default 'settings.json'
* @return {function} with the fetch process results
*/
function fetchSettings(path = 'settings.json') {
return _http.default.get(path, {
onResponse: response => receiveSettings(response),
onError: error => errorWithSettings(error)
});
}
//# sourceMappingURL=settingsActions.js.map
;