@c2dh/react-miller
Advanced tools
Comparing version 1.0.0-beta.7 to 1.0.0-beta.8
@@ -55,15 +55,57 @@ 'use strict'; | ||
apiUrl = _useContext.apiUrl, | ||
headers = _useContext.headers; | ||
headers = _useContext.headers, | ||
requestsCache = _useContext.requestsCache; | ||
return react.useCallback(function (path) { | ||
var req = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return axios__default["default"].get("".concat(apiUrl).concat(path), _objectSpread__default["default"](_objectSpread__default["default"]({ | ||
headers: headers | ||
}, req), {}, { | ||
// TODO: Fix encoding of facets avoid facets[] | ||
params: req.params ? encodeParamasForMiller(req.params) : undefined | ||
})).then(function (r) { | ||
return r.data; | ||
}); | ||
}, [apiUrl]); | ||
return react.useCallback( /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(path) { | ||
var req, | ||
url, | ||
data, | ||
_args = arguments; | ||
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
req = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}; | ||
url = "".concat(apiUrl).concat(path); | ||
if (!(requestsCache && requestsCache.has(url))) { | ||
_context.next = 4; | ||
break; | ||
} | ||
return _context.abrupt("return", requestsCache.get(url)); | ||
case 4: | ||
_context.next = 6; | ||
return axios__default["default"].get(url, _objectSpread__default["default"](_objectSpread__default["default"]({ | ||
headers: headers | ||
}, req), {}, { | ||
// TODO: Fix encoding of facets avoid facets[] | ||
params: req.params ? encodeParamasForMiller(req.params) : undefined | ||
})).then(function (r) { | ||
return r.data; | ||
}); | ||
case 6: | ||
data = _context.sent; | ||
if (requestsCache) { | ||
requestsCache.set(url, data); | ||
} | ||
return _context.abrupt("return", data); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(), [apiUrl]); | ||
} | ||
@@ -245,3 +287,4 @@ | ||
headers = _ref.headers, | ||
children = _ref.children; | ||
children = _ref.children, | ||
requestsCache = _ref.requestsCache; | ||
var value = react.useMemo(function () { | ||
@@ -253,5 +296,6 @@ return { | ||
langs: langs, | ||
headers: headers | ||
headers: headers, | ||
requestsCache: requestsCache | ||
}; | ||
}, [apiUrl, lang, fallbackLang, langs, headers]); | ||
}, [apiUrl, lang, fallbackLang, langs, headers, requestsCache]); | ||
return /*#__PURE__*/jsxRuntime.jsx(reactQuery.QueryClientProvider, { | ||
@@ -258,0 +302,0 @@ client: client, |
import { ReactNode } from 'react'; | ||
import { InfiniteData, QueryClient, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseQueryOptions, UseQueryResult } from 'react-query'; | ||
import { MillerConfig, MillerDocumenntInList, MillerDocumentDetail, MillerFacetsResponse, MillerPaginatedResponse, MillerPaginatedResponseWithFacets, MillerStory, MillerStoryWithChapters } from './types'; | ||
export declare function Miller({ client, apiUrl, lang, fallbackLang, langs, headers, children, }: MillerConfig & { | ||
export declare function Miller({ client, apiUrl, lang, fallbackLang, langs, headers, children, requestsCache, }: MillerConfig & { | ||
client: QueryClient; | ||
@@ -6,0 +6,0 @@ children: ReactNode; |
@@ -41,15 +41,57 @@ import _toConsumableArray from '@babel/runtime/helpers/esm/toConsumableArray'; | ||
apiUrl = _useContext.apiUrl, | ||
headers = _useContext.headers; | ||
headers = _useContext.headers, | ||
requestsCache = _useContext.requestsCache; | ||
return useCallback(function (path) { | ||
var req = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return axios.get("".concat(apiUrl).concat(path), _objectSpread(_objectSpread({ | ||
headers: headers | ||
}, req), {}, { | ||
// TODO: Fix encoding of facets avoid facets[] | ||
params: req.params ? encodeParamasForMiller(req.params) : undefined | ||
})).then(function (r) { | ||
return r.data; | ||
}); | ||
}, [apiUrl]); | ||
return useCallback( /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(path) { | ||
var req, | ||
url, | ||
data, | ||
_args = arguments; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
req = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}; | ||
url = "".concat(apiUrl).concat(path); | ||
if (!(requestsCache && requestsCache.has(url))) { | ||
_context.next = 4; | ||
break; | ||
} | ||
return _context.abrupt("return", requestsCache.get(url)); | ||
case 4: | ||
_context.next = 6; | ||
return axios.get(url, _objectSpread(_objectSpread({ | ||
headers: headers | ||
}, req), {}, { | ||
// TODO: Fix encoding of facets avoid facets[] | ||
params: req.params ? encodeParamasForMiller(req.params) : undefined | ||
})).then(function (r) { | ||
return r.data; | ||
}); | ||
case 6: | ||
data = _context.sent; | ||
if (requestsCache) { | ||
requestsCache.set(url, data); | ||
} | ||
return _context.abrupt("return", data); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(), [apiUrl]); | ||
} | ||
@@ -231,3 +273,4 @@ | ||
headers = _ref.headers, | ||
children = _ref.children; | ||
children = _ref.children, | ||
requestsCache = _ref.requestsCache; | ||
var value = useMemo(function () { | ||
@@ -239,5 +282,6 @@ return { | ||
langs: langs, | ||
headers: headers | ||
headers: headers, | ||
requestsCache: requestsCache | ||
}; | ||
}, [apiUrl, lang, fallbackLang, langs, headers]); | ||
}, [apiUrl, lang, fallbackLang, langs, headers, requestsCache]); | ||
return /*#__PURE__*/jsx(QueryClientProvider, { | ||
@@ -244,0 +288,0 @@ client: client, |
@@ -22,2 +22,7 @@ export interface MillerConfig { | ||
headers?: RequestHeaders; | ||
/** | ||
* Global request cache, used as global cache when staticize a Miller Based Site | ||
* | ||
*/ | ||
requestsCache?: Map<string, any>; | ||
} | ||
@@ -24,0 +29,0 @@ export declare type RequestHeaders = Record<string, string | number | boolean>; |
@@ -5,3 +5,3 @@ { | ||
"license": "AGPL-3.0", | ||
"version": "1.0.0-beta.7", | ||
"version": "1.0.0-beta.8", | ||
"author": "c2dh (https://c2dh.uni.lu)", | ||
@@ -8,0 +8,0 @@ "main": "dist/index.cjs.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82354
1194