diff options
| author | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
|---|---|---|
| committer | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
| commit | bce557cc2dc767628bed6aac87301a1be7c5431b (patch) | |
| tree | b51a051228d01fe3306cd7626d4a96768aadb944 /node_modules/@jet/engine/lib/metrics/presenters | |
init commit
Diffstat (limited to 'node_modules/@jet/engine/lib/metrics/presenters')
| -rw-r--r-- | node_modules/@jet/engine/lib/metrics/presenters/index.js | 13 | ||||
| -rw-r--r-- | node_modules/@jet/engine/lib/metrics/presenters/page-metrics-presenter.js | 52 |
2 files changed, 65 insertions, 0 deletions
diff --git a/node_modules/@jet/engine/lib/metrics/presenters/index.js b/node_modules/@jet/engine/lib/metrics/presenters/index.js new file mode 100644 index 0000000..56e55cf --- /dev/null +++ b/node_modules/@jet/engine/lib/metrics/presenters/index.js @@ -0,0 +1,13 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./page-metrics-presenter"), exports); diff --git a/node_modules/@jet/engine/lib/metrics/presenters/page-metrics-presenter.js b/node_modules/@jet/engine/lib/metrics/presenters/page-metrics-presenter.js new file mode 100644 index 0000000..9dd1eff --- /dev/null +++ b/node_modules/@jet/engine/lib/metrics/presenters/page-metrics-presenter.js @@ -0,0 +1,52 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PageMetricsPresenter = void 0; +const optional_1 = require("@jet/environment/types/optional"); +class PageMetricsPresenter { + constructor(metricsPipeline) { + this.metricsPipeline = metricsPipeline; + this.isViewAppeared = false; + } + set pageMetrics(pageMetrics) { + this.pageMetricsStore = pageMetrics; + if (optional_1.isSome(pageMetrics) && this.isViewAppeared) { + void this.processInstructions("pageEnter"); + } + } + get pageMetrics() { + return this.pageMetricsStore; + } + async processInstructions(invocationPoint) { + var _a, _b, _c; + if (optional_1.isNothing(this.pageMetrics)) { + return; + } + // istanbul ignore next + const invocationContext = { + customMetrics: (_a = this.baseContext) === null || _a === void 0 ? void 0 : _a.customMetrics, + pageFields: { + ...(_b = this.baseContext) === null || _b === void 0 ? void 0 : _b.pageFields, + ...(_c = this.pageMetrics) === null || _c === void 0 ? void 0 : _c.pageFields, + }, + }; + await Promise.all(this.pageMetrics.instructions.map((instruction) => { + const { invocationPoints } = instruction; + if (invocationPoints.length === 0 || !invocationPoints.includes(invocationPoint)) { + return; + } + // eslint-disable-next-line @typescript-eslint/no-floating-promises + return this.metricsPipeline.process(instruction.data, invocationContext); + })); + } + async didEnterPage() { + this.isViewAppeared = true; + if (optional_1.isSome(this.pageMetrics)) { + await this.processInstructions("pageEnter"); + } + } + async didLeavePage() { + await this.processInstructions("pageExit"); + this.isViewAppeared = false; + } +} +exports.PageMetricsPresenter = PageMetricsPresenter; |
