react-clear-cache
Advanced tools
Comparing version 1.1.0 to 1.1.1
import * as React from 'react'; | ||
declare const defaultProps: { | ||
duration: number; | ||
auto: boolean; | ||
storageKey: string; | ||
}; | ||
declare type OwnProps = { | ||
duration?: number; | ||
auto?: boolean; | ||
children?: any; | ||
}; | ||
export declare function useClearCache(props?: OwnProps): { | ||
} & typeof defaultProps; | ||
export declare const useClearCache: (props: OwnProps) => { | ||
loading: boolean; | ||
@@ -9,0 +12,0 @@ isLatestVersion: boolean; |
@@ -18,2 +18,13 @@ import { useRef, useEffect, useState } from 'react'; | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
@@ -60,11 +71,16 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
function useClearCache(props) { | ||
var _this = this; | ||
if (props === void 0) { props = {}; } | ||
var _a = props.duration, duration = _a === void 0 ? 60 * 1000 : _a, _b = props.auto, auto = _b === void 0 ? false : _b; | ||
var _c = useState(true), loading = _c[0], setLoading = _c[1]; | ||
var _this = undefined; | ||
var STORAGE_KEY = 'APP_VERSION'; | ||
var defaultProps = { | ||
duration: 60 * 1000, | ||
auto: false, | ||
storageKey: STORAGE_KEY | ||
}; | ||
var useClearCache = function (props) { | ||
var _a = __assign({}, defaultProps, props), duration = _a.duration, auto = _a.auto, storageKey = _a.storageKey; | ||
var _b = useState(true), loading = _b[0], setLoading = _b[1]; | ||
var useAppVersionState = createPersistedState(storageKey); | ||
var _c = useAppVersionState(''), appVersion = _c[0], setAppVersion = _c[1]; | ||
var _d = useState(true), isLatestVersion = _d[0], setIsLatestVersion = _d[1]; | ||
var useAppVersionState = createPersistedState('appVersion'); | ||
var _e = useAppVersionState(''), appVersion = _e[0], setAppVersion = _e[1]; | ||
var _f = useState(appVersion), latestVersion = _f[0], setLatestVersion = _f[1]; | ||
var _e = useState(appVersion), latestVersion = _e[0], setLatestVersion = _e[1]; | ||
function setVersion(version) { | ||
@@ -86,3 +102,2 @@ return __awaiter(this, void 0, void 0, function () { | ||
case 0: | ||
console.log('Clearing cache and hard reloading...'); | ||
if ('caches' in window) { | ||
@@ -122,3 +137,8 @@ // Service worker cache should be cleared with caches.delete() | ||
setLoading(false); | ||
setIsLatestVersion(false); | ||
if (appVersion) { | ||
setIsLatestVersion(false); | ||
} | ||
else { | ||
setVersion(newVersion); | ||
} | ||
} | ||
@@ -144,5 +164,8 @@ else if (!isUpdated && auto) { | ||
return { | ||
loading: loading, isLatestVersion: isLatestVersion, emptyCacheStorage: emptyCacheStorage, latestVersion: latestVersion | ||
loading: loading, | ||
isLatestVersion: isLatestVersion, | ||
emptyCacheStorage: emptyCacheStorage, | ||
latestVersion: latestVersion | ||
}; | ||
} | ||
}; | ||
var ClearCache = function (props) { | ||
@@ -149,0 +172,0 @@ var _a = useClearCache(props), loading = _a.loading, isLatestVersion = _a.isLatestVersion, emptyCacheStorage = _a.emptyCacheStorage; |
@@ -22,2 +22,13 @@ 'use strict'; | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
@@ -64,11 +75,16 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
function useClearCache(props) { | ||
var _this = this; | ||
if (props === void 0) { props = {}; } | ||
var _a = props.duration, duration = _a === void 0 ? 60 * 1000 : _a, _b = props.auto, auto = _b === void 0 ? false : _b; | ||
var _c = React.useState(true), loading = _c[0], setLoading = _c[1]; | ||
var _this = undefined; | ||
var STORAGE_KEY = 'APP_VERSION'; | ||
var defaultProps = { | ||
duration: 60 * 1000, | ||
auto: false, | ||
storageKey: STORAGE_KEY | ||
}; | ||
var useClearCache = function (props) { | ||
var _a = __assign({}, defaultProps, props), duration = _a.duration, auto = _a.auto, storageKey = _a.storageKey; | ||
var _b = React.useState(true), loading = _b[0], setLoading = _b[1]; | ||
var useAppVersionState = createPersistedState(storageKey); | ||
var _c = useAppVersionState(''), appVersion = _c[0], setAppVersion = _c[1]; | ||
var _d = React.useState(true), isLatestVersion = _d[0], setIsLatestVersion = _d[1]; | ||
var useAppVersionState = createPersistedState('appVersion'); | ||
var _e = useAppVersionState(''), appVersion = _e[0], setAppVersion = _e[1]; | ||
var _f = React.useState(appVersion), latestVersion = _f[0], setLatestVersion = _f[1]; | ||
var _e = React.useState(appVersion), latestVersion = _e[0], setLatestVersion = _e[1]; | ||
function setVersion(version) { | ||
@@ -90,3 +106,2 @@ return __awaiter(this, void 0, void 0, function () { | ||
case 0: | ||
console.log('Clearing cache and hard reloading...'); | ||
if ('caches' in window) { | ||
@@ -126,3 +141,8 @@ // Service worker cache should be cleared with caches.delete() | ||
setLoading(false); | ||
setIsLatestVersion(false); | ||
if (appVersion) { | ||
setIsLatestVersion(false); | ||
} | ||
else { | ||
setVersion(newVersion); | ||
} | ||
} | ||
@@ -148,5 +168,8 @@ else if (!isUpdated && auto) { | ||
return { | ||
loading: loading, isLatestVersion: isLatestVersion, emptyCacheStorage: emptyCacheStorage, latestVersion: latestVersion | ||
loading: loading, | ||
isLatestVersion: isLatestVersion, | ||
emptyCacheStorage: emptyCacheStorage, | ||
latestVersion: latestVersion | ||
}; | ||
} | ||
}; | ||
var ClearCache = function (props) { | ||
@@ -153,0 +176,0 @@ var _a = useClearCache(props), loading = _a.loading, isLatestVersion = _a.isLatestVersion, emptyCacheStorage = _a.emptyCacheStorage; |
{ | ||
"name": "react-clear-cache", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A component to manage application updates.", | ||
@@ -29,3 +29,6 @@ "author": "noahjohn9259", | ||
"predeploy": "cd example && npm install && npm run build", | ||
"deploy": "gh-pages -d example/build" | ||
"deploy": "gh-pages -d example/build", | ||
"release:major": "npm version major && git push origin && git push origin --tags", | ||
"release:minor": "npm version minor && git push origin && git push origin --tags", | ||
"release:patch": "npm version patch && git push origin && git push origin --tags" | ||
}, | ||
@@ -32,0 +35,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
72531
384