UNPKG

next

Version:

The React Framework

64 lines (62 loc) 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 0 && (module.exports = { callServer: null, useServerActionDispatcher: null }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { callServer: function() { return callServer; }, useServerActionDispatcher: function() { return useServerActionDispatcher; } }); const _react = require("react"); const _routerreducertypes = require("./components/router-reducer/router-reducer-types"); let globalServerActionDispatcher = null; function useServerActionDispatcher(dispatch) { const serverActionDispatcher = (0, _react.useCallback)((actionPayload)=>{ (0, _react.startTransition)(()=>{ dispatch({ ...actionPayload, type: _routerreducertypes.ACTION_SERVER_ACTION }); }); }, [ dispatch ]); globalServerActionDispatcher = serverActionDispatcher; } async function callServer(actionId, actionArgs) { const actionDispatcher = globalServerActionDispatcher; if (!actionDispatcher) { throw Object.defineProperty(new Error('Invariant: missing action dispatcher.'), "__NEXT_ERROR_CODE", { value: "E507", enumerable: false, configurable: true }); } return new Promise((resolve, reject)=>{ actionDispatcher({ actionId, actionArgs, resolve, reject }); }); } if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') { Object.defineProperty(exports.default, '__esModule', { value: true }); Object.assign(exports.default, exports); module.exports = exports.default; } //# sourceMappingURL=app-call-server.js.map