@netlify/content-engine
Version:
33 lines • 1.29 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.callRealApi = void 0;
const assert_store_1 = require("./assert-store");
const actions_1 = require("../redux/actions");
const reporter_1 = __importDefault(require("../reporter"));
/**
* These are the deferred redux actions sent from api-runner-node
* They may include a `resolve` prop (if they are createNode actions).
* If so, we resolve the promise when we're done
*/
const callRealApi = (event, store) => {
(0, assert_store_1.assertStore)(store);
const { type, payload, resolve } = event;
if (type in actions_1.actions) {
// If this is a createNode action then this will be a thunk.
// No worries, we just dispatch it like any other
const action = actions_1.actions[type](...payload);
const result = store.dispatch(action);
// Somebody may be waiting for this
if (resolve) {
resolve(result);
}
}
else {
reporter_1.default.log(`Could not dispatch unknown action "${type}`);
}
};
exports.callRealApi = callRealApi;
//# sourceMappingURL=call-deferred-api.js.map
;