Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4e0e094
Collect property metrics in one module.
KaramanisDev Nov 16, 2026
8f25423
Sort booked countries without mutating them.
KaramanisDev Nov 16, 2026
12b484b
Skip scheduling results of a replaced search.
KaramanisDev Nov 16, 2026
f7f76d2
Move Hostelworld app hooks into a page module.
KaramanisDev Nov 17, 2026
0de4f08
Move property card lookups into the page module.
KaramanisDev Nov 17, 2026
8780a3b
Move page placements into the page module.
KaramanisDev Nov 17, 2026
a462865
Abort the previous load-all on new results.
KaramanisDev Nov 17, 2026
08857ef
Retry a property page that failed to load.
KaramanisDev Nov 17, 2026
ae32e4b
Skip a property list Vue is tearing down.
KaramanisDev Nov 17, 2026
e0eb586
Show the filter button after in-app navigation.
KaramanisDev Nov 17, 2026
808871a
Ignore results of a replaced search.
KaramanisDev Nov 17, 2026
0756654
Treat a failed load-all as nothing to add.
KaramanisDev Nov 17, 2026
664155d
Let property cards decide which stay they show.
KaramanisDev Nov 17, 2026
d98a673
Release pinned guest flags before updating them.
KaramanisDev Nov 17, 2026
6b63dbe
Check the shown stay when card data lands.
KaramanisDev Nov 17, 2026
cdc2cef
Skip loading cards when no stay is shown.
KaramanisDev Nov 17, 2026
d00b348
Clear card data when the search stay changes.
KaramanisDev Nov 17, 2026
6dc609d
Split the RPC endpoint into relay and server.
KaramanisDev Nov 17, 2026
50a5639
Let the RPC proxy install its own recovery.
KaramanisDev Nov 17, 2026
8886479
Return each worker result to its own call.
KaramanisDev Nov 17, 2026
65735af
Free metric slots only for their own run.
KaramanisDev Nov 17, 2026
975df18
Attach the rating to reviews on the page side.
KaramanisDev Nov 17, 2026
59ecbd7
Forget worker requests whose task failed.
KaramanisDev Nov 17, 2026
971afa6
Type event payloads through an event catalogue.
KaramanisDev Nov 17, 2026
f1b5ef9
Let the Session DTO own the current context.
KaramanisDev Nov 17, 2026
4041072
Move shared data shapes into Types.
KaramanisDev Nov 17, 2026
15803af
Compose properties in the metrics buffer.
KaramanisDev Nov 17, 2026
b457a05
Rename ScheduledProperty to MetricsProperty.
KaramanisDev Nov 17, 2026
960b3bf
Clear collected metrics when work is cancelled.
KaramanisDev Nov 17, 2026
3de07b4
Rename the search page hook to a request tracker.
KaramanisDev Nov 17, 2026
2786486
Name the search filter steps after what they do.
KaramanisDev Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/app/Communication/RPCProtocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export class RPCProtocol {
public static readonly callEvent: string = 'rpc:call'
public static readonly resultEvent: string = 'rpc:result'
public static readonly cancelEvent: string = 'rpc:cancel'
public static readonly interruptedEvent: string = 'rpc:interrupted'
public static readonly disconnectedEvent: string = 'rpc:disconnected'
public static readonly cancelMessage: string = 'rpc:cancel'
public static readonly documentPortName: string = 'rpc:document'
private static readonly requestSuffix: string = ':request'
private static readonly responseSuffix: string = ':response'

public static requestMessage (task: string): string {
return `${task}${this.requestSuffix}`
}

public static responseMessage (task: string): string {
return `${task}${this.responseSuffix}`
}

public static requestedTask (message: string): string | null {
return this.taskOf(message, this.requestSuffix)
}

public static respondedTask (message: string): string | null {
return this.taskOf(message, this.responseSuffix)
}

private static taskOf (message: string, suffix: string): string | null {
return message.endsWith(suffix) ? message.slice(0, -suffix.length) : null
}
}
133 changes: 0 additions & 133 deletions src/app/Communication/WorkerRPCEndpoint.ts

This file was deleted.

73 changes: 40 additions & 33 deletions src/app/Communication/WorkerRPCProxy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { RPCCancelPayload, RPCRequest, RPCResult } from './RPCTypesContract'
import { RPCSerializer } from './RPCSerializer'
import type { WorkerTaskArgs, WorkerTaskName } from 'WorkerTasks/WorkerTaskCatalogue'

type RPCResultHandler<T = unknown> = (event: string, response: T) => void
import { RPCProtocol } from './RPCProtocol'
import type { WorkerTaskArgs, WorkerTaskName, WorkerTaskPayload } from 'WorkerTasks/WorkerTaskCatalogue'

type PendingCall = {
request: RPCRequest<string>
attempts: number
resolve: (result: unknown) => void
}

export class WorkerRPCProxy {
Expand All @@ -17,16 +17,24 @@ export class WorkerRPCProxy {
private static lastActivityAt: number = 0
private static silenceCheck: ReturnType<typeof setInterval> | null = null
private static isDisconnected: boolean = false
private static areListenersInstalled: boolean = false

public static call<TTask extends WorkerTaskName> (task: TTask, ...args: WorkerTaskArgs<TTask>): void {
if (this.isDisconnected) return
public static call<TTask extends WorkerTaskName> (
task: TTask,
...args: WorkerTaskArgs<TTask>
): Promise<WorkerTaskPayload<TTask>> {
return new Promise((resolve: (result: WorkerTaskPayload<TTask>) => void): void => {
if (this.isDisconnected) return

const request: RPCRequest<string> = { id: crypto.randomUUID(), task, args: RPCSerializer.serialize(args) }
this.installListeners()

this.pendingCalls.set(request.id, { request, attempts: 1 })
this.lastActivityAt = Date.now()
this.send(request)
this.watchForSilence()
const request: RPCRequest<string> = { id: crypto.randomUUID(), task, args: RPCSerializer.serialize(args) }

this.pendingCalls.set(request.id, { request, attempts: 1, resolve: resolve as (result: unknown) => void })
this.lastActivityAt = Date.now()
this.send(request)
this.watchForSilence()
})
}

public static cancelPending (): void {
Expand All @@ -36,48 +44,47 @@ export class WorkerRPCProxy {
this.pendingCalls.clear()

window.dispatchEvent(
new CustomEvent('rpc:cancel', { detail: payload })
new CustomEvent(RPCProtocol.cancelEvent, { detail: payload })
)
}

public static onResult<TResult = unknown> (callback: RPCResultHandler<TResult>): void {
window.addEventListener('rpc:result', (eventInit: CustomEventInit<RPCResult<string>>): void => {
if (!eventInit.detail) return

const { id, task, result } = eventInit.detail
if (this.pendingCalls.get(id)?.request.task !== task) return
public static onDisconnect (callback: () => void): void {
window.addEventListener(RPCProtocol.disconnectedEvent, (): void => {
if (this.isDisconnected) return

this.pendingCalls.delete(id)
this.lastActivityAt = Date.now()
callback(task, RPCSerializer.deserialize<TResult>(result))
this.isDisconnected = true
this.pendingCalls.clear()
callback()
})
}

public static resendOnPageRestore (): void {
private static installListeners (): void {
if (this.areListenersInstalled) return
this.areListenersInstalled = true

window.addEventListener(RPCProtocol.resultEvent, (eventInit: CustomEventInit<RPCResult<string>>): void => {
if (eventInit.detail) this.deliver(eventInit.detail)
})
window.addEventListener('pageshow', (event: PageTransitionEvent): void => {
if (!event.persisted) return

this.resendPending()
})
window.addEventListener(RPCProtocol.interruptedEvent, (): void => this.resendPending())
}

public static resendOnInterruption (): void {
window.addEventListener('rpc:interrupted', (): void => this.resendPending())
}

public static onDisconnect (callback: () => void): void {
window.addEventListener('rpc:disconnected', (): void => {
if (this.isDisconnected) return
private static deliver (result: RPCResult<string>): void {
const pendingCall: PendingCall | undefined = this.pendingCalls.get(result.id)
if (pendingCall?.request.task !== result.task) return

this.isDisconnected = true
this.pendingCalls.clear()
callback()
})
this.pendingCalls.delete(result.id)
this.lastActivityAt = Date.now()
pendingCall.resolve(RPCSerializer.deserialize(result.result))
}

private static send (request: RPCRequest<string>): void {
window.dispatchEvent(
new CustomEvent('rpc:call', { detail: request })
new CustomEvent(RPCProtocol.callEvent, { detail: request })
)
}

Expand Down
53 changes: 53 additions & 0 deletions src/app/Communication/WorkerRPCRelay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ExtensionRuntime } from 'Utils/ExtensionRuntime'
import type { RPCCancelPayload, RPCRequest, RPCRequestPayload, RPCResponsePayload, RPCResult } from './RPCTypesContract'
import { RPCProtocol } from './RPCProtocol'

export class WorkerRPCRelay {
private static isDocumentPortOpen: boolean = false

public static listen (): void {
ExtensionRuntime.onMessage((message: string, payload: RPCResponsePayload): void => {
const task: string | null = RPCProtocol.respondedTask(message)
if (!task) return

const result: RPCResult<string> = { id: payload.id, task, result: payload.result }

window.dispatchEvent(
new CustomEvent(RPCProtocol.resultEvent, { detail: result })
)
})

window.addEventListener(RPCProtocol.callEvent, (eventInit: CustomEventInit<RPCRequest<string>>): void => {
if (!eventInit.detail) return

if (!ExtensionRuntime.isConnected()) {
window.dispatchEvent(new CustomEvent(RPCProtocol.disconnectedEvent))

return
}

const { id, task, args } = eventInit.detail
const payload: RPCRequestPayload = { id, args }

this.openDocumentPort()
ExtensionRuntime.sendMessage(RPCProtocol.requestMessage(task), payload)
})

window.addEventListener(RPCProtocol.cancelEvent, (eventInit: CustomEventInit<RPCCancelPayload>): void => {
if (!eventInit.detail || !ExtensionRuntime.isConnected()) return

ExtensionRuntime.sendMessage(RPCProtocol.cancelMessage, eventInit.detail)
})
}

private static openDocumentPort (): void {
if (this.isDocumentPortOpen) return

this.isDocumentPortOpen = true
ExtensionRuntime.connect(RPCProtocol.documentPortName, (): void => {
this.isDocumentPortOpen = false

window.dispatchEvent(new CustomEvent(RPCProtocol.interruptedEvent))
})
}
}
Loading
Loading