/* Предрейсовые осмотры - мобильное приложение Провайдер контекста работы с сервером приложений */ //--------------------- //Подключение библиотек //--------------------- const React = require('react'); //React и хуки const useAppServer = require('../../hooks/useAppServer'); //Хук сервера приложений //----------- //Тело модуля //----------- //Контекст работы с сервером const AppServerContext = React.createContext(null); //Провайдер сервера приложений function AppServerProvider({ children }) { const api = useAppServer(); const value = React.useMemo( () => ({ executeAction: api.executeAction, abort: api.abort, isRespErr: api.isRespErr, getRespErrMessage: api.getRespErrMessage, RESP_STATUS_OK: api.RESP_STATUS_OK, RESP_STATUS_ERR: api.RESP_STATUS_ERR }), [api.abort, api.executeAction, api.getRespErrMessage, api.isRespErr, api.RESP_STATUS_ERR, api.RESP_STATUS_OK] ); return {children}; } //Хук доступа к контексту сервера приложений function useAppServerContext() { const ctx = React.useContext(AppServerContext); if (!ctx) { throw new Error('useAppServerContext должен использоваться внутри AppServerProvider'); } return ctx; } //---------------- //Интерфейс модуля //---------------- module.exports = { AppServerProvider, useAppServerContext };