@next-core/runtime 1.29.1 → 1.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/internal/Renderer.js +9 -3
- package/dist/cjs/internal/Renderer.js.map +1 -1
- package/dist/cjs/internal/RendererContext.js +41 -37
- package/dist/cjs/internal/RendererContext.js.map +1 -1
- package/dist/cjs/internal/Router.js +2 -2
- package/dist/cjs/internal/Router.js.map +1 -1
- package/dist/cjs/internal/bindListeners.js +20 -17
- package/dist/cjs/internal/bindListeners.js.map +1 -1
- package/dist/cjs/internal/historyExtended.js +3 -1
- package/dist/cjs/internal/historyExtended.js.map +1 -1
- package/dist/cjs/internal/poll.js +21 -12
- package/dist/cjs/internal/poll.js.map +1 -1
- package/dist/esm/internal/Renderer.js +10 -4
- package/dist/esm/internal/Renderer.js.map +1 -1
- package/dist/esm/internal/RendererContext.js +6 -2
- package/dist/esm/internal/RendererContext.js.map +1 -1
- package/dist/esm/internal/Router.js +2 -2
- package/dist/esm/internal/Router.js.map +1 -1
- package/dist/esm/internal/bindListeners.js +19 -16
- package/dist/esm/internal/bindListeners.js.map +1 -1
- package/dist/esm/internal/historyExtended.js +3 -1
- package/dist/esm/internal/historyExtended.js.map +1 -1
- package/dist/esm/internal/poll.js +17 -9
- package/dist/esm/internal/poll.js.map +1 -1
- package/dist/types/internal/historyExtended.d.ts +1 -0
- package/dist/types/internal/poll.d.ts +2 -1
- package/package.json +6 -6
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import { pick } from "lodash";
|
|
2
3
|
import { _internalApiGetRenderId } from "./Runtime.js";
|
|
4
|
+
import { computeRealValue } from "./compute/computeRealValue.js";
|
|
3
5
|
var timeoutIdList = new Set();
|
|
4
|
-
export function startPoll(task, _ref,
|
|
6
|
+
export function startPoll(task, _ref, pollOptions, runtimeContext) {
|
|
5
7
|
var {
|
|
6
8
|
progress,
|
|
7
9
|
success,
|
|
8
10
|
error,
|
|
9
11
|
finally: finallyCallback
|
|
10
12
|
} = _ref;
|
|
13
|
+
var {
|
|
14
|
+
expectPollStopImmediately,
|
|
15
|
+
expectPollEnd
|
|
16
|
+
} = pollOptions;
|
|
11
17
|
var {
|
|
12
18
|
interval,
|
|
13
19
|
leadingRequestDelay,
|
|
14
20
|
continueOnError,
|
|
15
|
-
delegateLoadingBar
|
|
16
|
-
|
|
17
|
-
expectPollStopImmediately
|
|
18
|
-
} = _ref2;
|
|
21
|
+
delegateLoadingBar
|
|
22
|
+
} = computeRealValue(pick(pollOptions, ["interval", "leadingRequestDelay", "continueOnError", "delegateLoadingBar"]), runtimeContext);
|
|
19
23
|
var currentRenderId = _internalApiGetRenderId();
|
|
20
24
|
var currentTimeoutId;
|
|
21
25
|
function poll() {
|
|
@@ -26,16 +30,19 @@ export function startPoll(task, _ref, _ref2) {
|
|
|
26
30
|
timeoutIdList.delete(currentTimeoutId);
|
|
27
31
|
var shouldStop;
|
|
28
32
|
try {
|
|
29
|
-
|
|
33
|
+
var _computeRealValue;
|
|
34
|
+
shouldStop = (_computeRealValue = computeRealValue(expectPollStopImmediately, runtimeContext)) === null || _computeRealValue === void 0 ? void 0 : _computeRealValue();
|
|
30
35
|
// Stop polling immediately when the expectation is match before task.
|
|
31
36
|
if (!shouldStop) {
|
|
37
|
+
var _computeRealValue2;
|
|
32
38
|
var _result = yield task();
|
|
33
39
|
// Stop polling immediately when the expectation is match or a different router
|
|
34
40
|
// is rendering after the task processed.
|
|
35
|
-
shouldStop = (expectPollStopImmediately === null ||
|
|
41
|
+
shouldStop = ((_computeRealValue2 = computeRealValue(expectPollStopImmediately, runtimeContext)) === null || _computeRealValue2 === void 0 ? void 0 : _computeRealValue2()) || currentRenderId !== _internalApiGetRenderId();
|
|
36
42
|
if (!shouldStop) {
|
|
43
|
+
var _computeRealValue3;
|
|
37
44
|
progress === null || progress === void 0 || progress(_result);
|
|
38
|
-
if (expectPollEnd !== null &&
|
|
45
|
+
if ((_computeRealValue3 = computeRealValue(expectPollEnd, runtimeContext)) !== null && _computeRealValue3 !== void 0 && _computeRealValue3(_result)) {
|
|
39
46
|
if (delegateLoadingBar) {
|
|
40
47
|
window.dispatchEvent(new Event("request.end"));
|
|
41
48
|
}
|
|
@@ -47,9 +54,10 @@ export function startPoll(task, _ref, _ref2) {
|
|
|
47
54
|
}
|
|
48
55
|
}
|
|
49
56
|
} catch (e) {
|
|
57
|
+
var _computeRealValue4;
|
|
50
58
|
// Stop polling immediately when the expectation is match or a different router
|
|
51
59
|
// is rendering after the task processed.
|
|
52
|
-
shouldStop = (expectPollStopImmediately === null ||
|
|
60
|
+
shouldStop = ((_computeRealValue4 = computeRealValue(expectPollStopImmediately, runtimeContext)) === null || _computeRealValue4 === void 0 ? void 0 : _computeRealValue4()) || currentRenderId !== _internalApiGetRenderId();
|
|
53
61
|
if (!shouldStop) {
|
|
54
62
|
error === null || error === void 0 || error(e);
|
|
55
63
|
if (continueOnError) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poll.js","names":["_internalApiGetRenderId","timeoutIdList","Set","startPoll","task","_ref","
|
|
1
|
+
{"version":3,"file":"poll.js","names":["pick","_internalApiGetRenderId","computeRealValue","timeoutIdList","Set","startPoll","task","_ref","pollOptions","runtimeContext","progress","success","error","finally","finallyCallback","expectPollStopImmediately","expectPollEnd","interval","leadingRequestDelay","continueOnError","delegateLoadingBar","currentRenderId","currentTimeoutId","poll","_poll","apply","arguments","_asyncToGenerator","delete","shouldStop","_computeRealValue","_computeRealValue2","result","_computeRealValue3","window","dispatchEvent","Event","delayedPoll","e","_computeRealValue4","delay","setTimeout","add","clearPollTimeout","timeoutId","clearTimeout","clear"],"sources":["../../../src/internal/poll.ts"],"sourcesContent":["import type { ProviderPollOptions } from \"@next-core/types\";\nimport { pick } from \"lodash\";\nimport { _internalApiGetRenderId } from \"./Runtime.js\";\nimport { computeRealValue } from \"./compute/computeRealValue.js\";\nimport { RuntimeContext } from \"./interfaces.js\";\n\nexport type PollableCallbackFunction = (result?: unknown) => unknown;\n\nexport interface PollableCallback {\n progress?: PollableCallbackFunction;\n success?: PollableCallbackFunction;\n error?: PollableCallbackFunction;\n finally?: PollableCallbackFunction;\n}\n\nconst timeoutIdList = new Set<number>();\n\nexport function startPoll(\n task: () => unknown,\n { progress, success, error, finally: finallyCallback }: PollableCallback,\n pollOptions: ProviderPollOptions,\n runtimeContext: RuntimeContext\n): void {\n const { expectPollStopImmediately, expectPollEnd } = pollOptions;\n const { interval, leadingRequestDelay, continueOnError, delegateLoadingBar } =\n computeRealValue(\n pick(pollOptions, [\n \"interval\",\n \"leadingRequestDelay\",\n \"continueOnError\",\n \"delegateLoadingBar\",\n ]),\n runtimeContext\n ) as ProviderPollOptions;\n const currentRenderId = _internalApiGetRenderId();\n let currentTimeoutId: number;\n async function poll(): Promise<void> {\n timeoutIdList.delete(currentTimeoutId);\n let shouldStop: boolean | undefined;\n try {\n shouldStop = (\n computeRealValue(expectPollStopImmediately, runtimeContext) as\n | (() => boolean)\n | undefined\n )?.();\n // Stop polling immediately when the expectation is match before task.\n if (!shouldStop) {\n const result = await task();\n // Stop polling immediately when the expectation is match or a different router\n // is rendering after the task processed.\n shouldStop =\n (\n computeRealValue(expectPollStopImmediately, runtimeContext) as\n | (() => boolean)\n | undefined\n )?.() || currentRenderId !== _internalApiGetRenderId();\n if (!shouldStop) {\n progress?.(result);\n if (\n (\n computeRealValue(expectPollEnd, runtimeContext) as\n | ((result: unknown) => boolean)\n | undefined\n )?.(result)\n ) {\n if (delegateLoadingBar) {\n window.dispatchEvent(new Event(\"request.end\"));\n }\n success?.(result);\n finallyCallback?.();\n } else {\n delayedPoll(interval ?? 3000);\n }\n }\n }\n } catch (e) {\n // Stop polling immediately when the expectation is match or a different router\n // is rendering after the task processed.\n shouldStop =\n (\n computeRealValue(expectPollStopImmediately, runtimeContext) as\n | (() => boolean)\n | undefined\n )?.() || currentRenderId !== _internalApiGetRenderId();\n if (!shouldStop) {\n error?.(e);\n if (continueOnError) {\n delayedPoll(interval ?? 3000);\n } else {\n finallyCallback?.();\n }\n }\n } finally {\n // Manually dispatch an event of `request.end` when the polling is stopped immediately.\n if (delegateLoadingBar && shouldStop) {\n window.dispatchEvent(new Event(\"request.end\"));\n }\n }\n }\n\n function delayedPoll(delay: number): void {\n currentTimeoutId = setTimeout(poll, delay) as unknown as number;\n timeoutIdList.add(currentTimeoutId);\n }\n\n delayedPoll(leadingRequestDelay ?? 0);\n\n if (delegateLoadingBar) {\n window.dispatchEvent(new Event(\"request.start\"));\n }\n}\n\nexport function clearPollTimeout(): void {\n for (const timeoutId of timeoutIdList) {\n clearTimeout(timeoutId);\n }\n timeoutIdList.clear();\n}\n"],"mappings":";AACA,SAASA,IAAI,QAAQ,QAAQ;AAC7B,SAASC,uBAAuB,QAAQ,cAAc;AACtD,SAASC,gBAAgB,QAAQ,+BAA+B;AAYhE,IAAMC,aAAa,GAAG,IAAIC,GAAG,CAAS,CAAC;AAEvC,OAAO,SAASC,SAASA,CACvBC,IAAmB,EAAAC,IAAA,EAEnBC,WAAgC,EAChCC,cAA8B,EACxB;EAAA,IAHN;IAAEC,QAAQ;IAAEC,OAAO;IAAEC,KAAK;IAAEC,OAAO,EAAEC;EAAkC,CAAC,GAAAP,IAAA;EAIxE,IAAM;IAAEQ,yBAAyB;IAAEC;EAAc,CAAC,GAAGR,WAAW;EAChE,IAAM;IAAES,QAAQ;IAAEC,mBAAmB;IAAEC,eAAe;IAAEC;EAAmB,CAAC,GAC1ElB,gBAAgB,CACdF,IAAI,CAACQ,WAAW,EAAE,CAChB,UAAU,EACV,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,CACrB,CAAC,EACFC,cACF,CAAwB;EAC1B,IAAMY,eAAe,GAAGpB,uBAAuB,CAAC,CAAC;EACjD,IAAIqB,gBAAwB;EAAC,SACdC,IAAIA,CAAA;IAAA,OAAAC,KAAA,CAAAC,KAAA,OAAAC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ACErC,gBAAgB,CAACa,yBAAyB,EAAEN,cAAc,CAAC,cAAA8B,kBAAA,uBAD7DA,kBAAA,CAII,CAAC,KAAIlB,eAAe,KAAKpB,uBAAuB,CAAC,CAAC;QACxD,IAAI,CAAC4B,UAAU,EAAE;UACfjB,KAAK,aAALA,KAAK,eAALA,KAAK,CAAG0B,CAAC,CAAC;UACV,IAAInB,eAAe,EAAE;YACnBkB,WAAW,CAACpB,QAAQ,aAARA,QAAQ,cAARA,QAAQ,GAAI,IAAI,CAAC;UAC/B,CAAC,MAAM;YACLH,eAAe,aAAfA,eAAe,eAAfA,eAAe,CAAG,CAAC;UACrB;QACF;MACF,CAAC,SAAS;QACR;QACA,IAAIM,kBAAkB,IAAIS,UAAU,EAAE;UACpCK,MAAM,CAACC,aAAa,CAAC,IAAIC,KAAK,CAAC,aAAa,CAAC,CAAC;QAChD;MACF;IACF,CAAC;IAAA,OAAAZ,KAAA,CAAAC,KAAA,OAAAC,SAAA;EAAA;EAED,SAASW,WAAWA,CAACG,KAAa,EAAQ;IACxClB,gBAAgB,GAAGmB,UAAU,CAAClB,IAAI,EAAEiB,KAAK,CAAsB;IAC/DrC,aAAa,CAACuC,GAAG,CAACpB,gBAAgB,CAAC;EACrC;EAEAe,WAAW,CAACnB,mBAAmB,aAAnBA,mBAAmB,cAAnBA,mBAAmB,GAAI,CAAC,CAAC;EAErC,IAAIE,kBAAkB,EAAE;IACtBc,MAAM,CAACC,aAAa,CAAC,IAAIC,KAAK,CAAC,eAAe,CAAC,CAAC;EAClD;AACF;AAEA,OAAO,SAASO,gBAAgBA,CAAA,EAAS;EACvC,KAAK,IAAMC,SAAS,IAAIzC,aAAa,EAAE;IACrC0C,YAAY,CAACD,SAAS,CAAC;EACzB;EACAzC,aAAa,CAAC2C,KAAK,CAAC,CAAC;AACvB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProviderPollOptions } from "@next-core/types";
|
|
2
|
+
import { RuntimeContext } from "./interfaces.js";
|
|
2
3
|
export type PollableCallbackFunction = (result?: unknown) => unknown;
|
|
3
4
|
export interface PollableCallback {
|
|
4
5
|
progress?: PollableCallbackFunction;
|
|
@@ -6,5 +7,5 @@ export interface PollableCallback {
|
|
|
6
7
|
error?: PollableCallbackFunction;
|
|
7
8
|
finally?: PollableCallbackFunction;
|
|
8
9
|
}
|
|
9
|
-
export declare function startPoll(task: () => unknown, { progress, success, error, finally: finallyCallback }: PollableCallback,
|
|
10
|
+
export declare function startPoll(task: () => unknown, { progress, success, error, finally: finallyCallback }: PollableCallback, pollOptions: ProviderPollOptions, runtimeContext: RuntimeContext): void;
|
|
10
11
|
export declare function clearPollTimeout(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/runtime",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.1",
|
|
4
4
|
"homepage": "https://github.com/easyops-cn/next-core/tree/v3/packages/runtime",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"repository": {
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"@next-core/color-theme": "^0.4.8",
|
|
47
47
|
"@next-core/cook": "^2.2.11",
|
|
48
48
|
"@next-core/http": "^1.1.8",
|
|
49
|
-
"@next-core/i18n": "^1.0.
|
|
50
|
-
"@next-core/inject": "^1.0.
|
|
49
|
+
"@next-core/i18n": "^1.0.37",
|
|
50
|
+
"@next-core/inject": "^1.0.27",
|
|
51
51
|
"@next-core/loader": "^1.5.3",
|
|
52
52
|
"@next-core/supply": "^2.1.10",
|
|
53
|
-
"@next-core/types": "^1.
|
|
54
|
-
"@next-core/utils": "^1.6.
|
|
53
|
+
"@next-core/types": "^1.8.0",
|
|
54
|
+
"@next-core/utils": "^1.6.9",
|
|
55
55
|
"@ungap/event-target": "^0.2.4",
|
|
56
56
|
"compare-versions": "^6.1.0",
|
|
57
57
|
"history": "^4.10.1",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"@next-core/build-next-libs": "^1.0.11",
|
|
67
67
|
"@next-core/test-next": "^1.0.14"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "89e30e2282454417da1c5c73f91586e121bd274d"
|
|
70
70
|
}
|