Skip to content

Commit

Permalink
feat(): v1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeshuTT committed Dec 7, 2023
1 parent 5a8461e commit ed8170d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 41 deletions.
1 change: 0 additions & 1 deletion dist/types/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export interface VersionPollingOptions {
appETagKey?: string;
pollingInterval?: number;
immediate: boolean;
htmlFileUrl: string;
silent?: boolean;
silentPollingInterval?: boolean;
Expand Down
26 changes: 14 additions & 12 deletions dist/version-polling.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* version-polling v1.2.0
* version-polling v1.2.2
* (c) 2023 JoeshuTT
* @license MIT
*/
Expand Down Expand Up @@ -50,7 +50,7 @@ function createWorker(func) {
return worker;
}
function createWorkerFunc() {
let timerId;
let timerId = null;
let options;
self.onmessage = event => {
let code = event.data["code"];
Expand All @@ -59,7 +59,6 @@ function createWorkerFunc() {
htmlFileUrl,
lastEtag,
appETagKey,
immediate,
pollingInterval,
silentPollingInterval
} = options;
Expand All @@ -81,16 +80,22 @@ function createWorkerFunc() {
}
});
};
if (code === "pause") {
clearInterval(timerId);
timerId = null;
} else if (code === "start") {
immediate && runReq();
const startPollingTask = () => {
if (!silentPollingInterval) {
timerId = setInterval(runReq, pollingInterval);
}
};
const pausePollingTask = () => {
if (timerId) {
clearInterval(timerId);
timerId = null;
}
};
if (code === "pause") {
pausePollingTask();
} else {
runReq();
runReq(); // 立即执行一次
startPollingTask();
}
};
return self;
Expand All @@ -104,7 +109,6 @@ let myWorker;
const defaultOptions = {
appETagKey: APP_ETAG_KEY,
pollingInterval: 5 * 60 * 1000,
immediate: true,
htmlFileUrl: `${location.origin}${location.pathname}`,
silent: false,
silentPollingInterval: false,
Expand Down Expand Up @@ -157,7 +161,6 @@ class VersionPolling {
const {
appETagKey,
pollingInterval,
immediate,
htmlFileUrl,
silent,
silentPollingInterval,
Expand All @@ -172,7 +175,6 @@ class VersionPolling {
data: {
appETagKey,
pollingInterval,
immediate,
htmlFileUrl,
silentPollingInterval,
lastEtag: this.appEtag
Expand Down
26 changes: 14 additions & 12 deletions dist/version-polling.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* version-polling v1.2.0
* version-polling v1.2.2
* (c) 2023 JoeshuTT
* @license MIT
*/
Expand Down Expand Up @@ -48,7 +48,7 @@ function createWorker(func) {
return worker;
}
function createWorkerFunc() {
let timerId;
let timerId = null;
let options;
self.onmessage = event => {
let code = event.data["code"];
Expand All @@ -57,7 +57,6 @@ function createWorkerFunc() {
htmlFileUrl,
lastEtag,
appETagKey,
immediate,
pollingInterval,
silentPollingInterval
} = options;
Expand All @@ -79,16 +78,22 @@ function createWorkerFunc() {
}
});
};
if (code === "pause") {
clearInterval(timerId);
timerId = null;
} else if (code === "start") {
immediate && runReq();
const startPollingTask = () => {
if (!silentPollingInterval) {
timerId = setInterval(runReq, pollingInterval);
}
};
const pausePollingTask = () => {
if (timerId) {
clearInterval(timerId);
timerId = null;
}
};
if (code === "pause") {
pausePollingTask();
} else {
runReq();
runReq(); // 立即执行一次
startPollingTask();
}
};
return self;
Expand All @@ -102,7 +107,6 @@ let myWorker;
const defaultOptions = {
appETagKey: APP_ETAG_KEY,
pollingInterval: 5 * 60 * 1000,
immediate: true,
htmlFileUrl: `${location.origin}${location.pathname}`,
silent: false,
silentPollingInterval: false,
Expand Down Expand Up @@ -155,7 +159,6 @@ class VersionPolling {
const {
appETagKey,
pollingInterval,
immediate,
htmlFileUrl,
silent,
silentPollingInterval,
Expand All @@ -170,7 +173,6 @@ class VersionPolling {
data: {
appETagKey,
pollingInterval,
immediate,
htmlFileUrl,
silentPollingInterval,
lastEtag: this.appEtag
Expand Down
26 changes: 14 additions & 12 deletions dist/version-polling.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* version-polling v1.2.0
* version-polling v1.2.2
* (c) 2023 JoeshuTT
* @license MIT
*/
Expand Down Expand Up @@ -54,7 +54,7 @@
return worker;
}
function createWorkerFunc() {
let timerId;
let timerId = null;
let options;
self.onmessage = event => {
let code = event.data["code"];
Expand All @@ -63,7 +63,6 @@
htmlFileUrl,
lastEtag,
appETagKey,
immediate,
pollingInterval,
silentPollingInterval
} = options;
Expand All @@ -85,16 +84,22 @@
}
});
};
if (code === "pause") {
clearInterval(timerId);
timerId = null;
} else if (code === "start") {
immediate && runReq();
const startPollingTask = () => {
if (!silentPollingInterval) {
timerId = setInterval(runReq, pollingInterval);
}
};
const pausePollingTask = () => {
if (timerId) {
clearInterval(timerId);
timerId = null;
}
};
if (code === "pause") {
pausePollingTask();
} else {
runReq();
runReq(); // 立即执行一次
startPollingTask();
}
};
return self;
Expand All @@ -108,7 +113,6 @@
const defaultOptions = {
appETagKey: APP_ETAG_KEY,
pollingInterval: 5 * 60 * 1000,
immediate: true,
htmlFileUrl: `${location.origin}${location.pathname}`,
silent: false,
silentPollingInterval: false,
Expand Down Expand Up @@ -161,7 +165,6 @@
const {
appETagKey,
pollingInterval,
immediate,
htmlFileUrl,
silent,
silentPollingInterval,
Expand All @@ -176,7 +179,6 @@
data: {
appETagKey,
pollingInterval,
immediate,
htmlFileUrl,
silentPollingInterval,
lastEtag: this.appEtag
Expand Down
4 changes: 2 additions & 2 deletions dist/version-polling.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "version-polling",
"version": "1.2.0",
"version": "1.2.2",
"description": "一个用于实时检测 web 应用更新的 JavaScript 库",
"engines": {
"node": ">=14"
Expand Down

0 comments on commit ed8170d

Please sign in to comment.