Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f3f00f2

Browse files
swConfig
1 parent c195b0f commit f3f00f2

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

‎client/src/index.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import './index.css';
77
import App from './App';
88
import * as serviceWorkerRegistration from './serviceWorkerRegistration';
99
import reportWebVitals from './reportWebVitals';
10+
import swConfig from './swConfig';
1011

1112
import 'bootstrap/dist/css/bootstrap.min.css';
1213
import 'bootstrap-icons/font/bootstrap-icons.css';
@@ -23,25 +24,8 @@ ReactDOM.render(
2324
// If you want your app to work offline and load faster, you can change
2425
// unregister() to register() below. Note this comes with some pitfalls.
2526
// Learn more about service workers: https://cra.link/PWA
26-
/**
27-
* Подключение ServiceWorker для PWA
28-
*/
29-
serviceWorkerRegistration.register({
30-
/**подключение обновителя */
31-
onUpdate: updater
32-
});
33-
34-
/**
35-
* Обновление кэша PWA
36-
* @param {*} registration
37-
*/
38-
function updater(registration) {
39-
alert('New version available! Ready to update?');
40-
if (registration && registration.waiting) {
41-
registration.waiting.postMessage({ type: 'SKIP_WAITING' });
42-
}
43-
window.location.reload();
44-
}
27+
/** Подключение ServiceWorker для PWA */
28+
serviceWorkerRegistration.register(swConfig);
4529

4630
// If you want to start measuring performance in your app, pass a function
4731
// to log results (for example: reportWebVitals(console.log))

‎client/src/swConfig.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/** @file swConfig.js */
2+
3+
/** Конфигурация serviceWorker */
4+
const swConfig = {
5+
onUpdate: updater,
6+
onSuccess: reghandler
7+
}
8+
9+
export default swConfig
10+
11+
/**
12+
* Обновление кэша PWA
13+
* @param {*} registration
14+
*/
15+
function updater(registration) {
16+
if (registration && registration.waiting) {
17+
registration.waiting.addEventListener("statechange", event => {
18+
if (event.target.state === "activated") {
19+
alert('New version available! Ready to update?')
20+
window.location.reload()
21+
console.info('service worker updated')
22+
}
23+
})
24+
registration.waiting.postMessage({ type: "SKIP_WAITING" })
25+
}
26+
}
27+
28+
/**
29+
* Обработка успешной регистрации сокета
30+
* @param {*} registration
31+
*/
32+
function reghandler() {
33+
console.info('service worker on success state')
34+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /