56 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Предрейсовые осмотры - мобильное приложение
Провайдер контекста работы с сервером приложений
*/
//---------------------
//Подключение библиотек
//---------------------
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 <AppServerContext.Provider value={value}>{children}</AppServerContext.Provider>;
}
//Хук доступа к контексту сервера приложений
function useAppServerContext() {
const ctx = React.useContext(AppServerContext);
if (!ctx) {
throw new Error('useAppServerContext должен использоваться внутри AppServerProvider');
}
return ctx;
}
//----------------
//Интерфейс модуля
//----------------
module.exports = {
AppServerProvider,
useAppServerContext
};