Refactor to remove some duplicated functiosn

This commit is contained in:
James Babcock committed 2026-07-26 11:33:16 -07:00
1 parent 797682a386
commit 205d393415
17 files changed
+57 -223

No files matched your search

-22
View File
@@ -1,22 +0,0 @@
/**
* Trivial echo worker: spike scaffolding for the app-shell architecture.
* Validates that worker chunks build under @nativescript/webpack, that
* message passing works in both directions, and that a worker isolate can
* call Java APIs directly.
*/
import "@nativescript/core/globals";
declare const global: any;
declare const java: any;
global.onmessage = (event: { data: any }) => {
// Direct Java call from the worker isolate: this runs on the worker's own
// JVM-attached thread, not the main thread.
const javaThreadName = String(java.lang.Thread.currentThread().getName());
global.postMessage({
type: "pong",
echoed: event.data,
workerJavaThreadName: javaThreadName,
workerReceivedAtMs: Date.now(),
});
};
+1 -3
View File
@@ -20,6 +20,7 @@ import {
GESTURE_DOUBLE_CLICK,
GESTURE_SCROLL,
} from "../ui/gestures";
import { clamp } from "../util/numeric-util";
declare const global: any;
declare const com: any;
@@ -579,6 +580,3 @@ function formatDuration(durationMs: number): string {
return `${seconds}s`;
}
function clamp(value: number, min: number, max: number): number {
return Math.max(min, Math.min(max, value));
}
-36
View File
@@ -1,36 +0,0 @@
/**
* Worker spike: spawn the echo worker, do one round trip, log the results.
* Temporary scaffolding for the app-shell architecture work; exercises the
* webpack worker chunk, bidirectional postMessage, and worker Java access.
* Results appear in logcat prefixed with "worker-spike:".
*/
declare const java: any;
export function runWorkerSpike(): void {
const mainJavaThreadName = String(java.lang.Thread.currentThread().getName());
console.log(`worker-spike: spawning echo worker (main thread=${mainJavaThreadName})`);
let worker: Worker;
try {
worker = new Worker("./echo.worker");
} catch (error) {
console.error(`worker-spike: failed to spawn worker: ${error}`);
return;
}
const sentAtMs = Date.now();
worker.onmessage = (event: MessageEvent) => {
const roundTripMs = Date.now() - sentAtMs;
console.log(
`worker-spike: reply received in ${roundTripMs}ms: ${JSON.stringify(event.data)}`,
);
worker.terminate();
console.log("worker-spike: worker terminated, spike complete");
};
worker.onerror = (error) => {
console.error(`worker-spike: worker error: ${JSON.stringify(error)}`);
worker.terminate();
};
worker.postMessage({ type: "ping", sentAtMs, payload: "hello from main" });
}