mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
add code to add/remove from subscriber array
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { GetterSetterRepository } from "./GetterSetterRepository";
|
||||
import { IEntityWithId, IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } from "../entities/entities";
|
||||
import { TupleKey } from "../types/TupleKey";
|
||||
|
||||
/**
|
||||
* An unoptimized in memory repository.
|
||||
@@ -14,6 +15,8 @@ export class UnoptimizedInMemoryRepository implements GetterSetterRepository {
|
||||
private etas: IEta[] = [];
|
||||
private orderedStops: IOrderedStop[] = [];
|
||||
|
||||
private subscribers: ((eta: IEta) => void)[] = [];
|
||||
|
||||
public async getSystems() {
|
||||
return this.systems;
|
||||
}
|
||||
@@ -59,9 +62,14 @@ export class UnoptimizedInMemoryRepository implements GetterSetterRepository {
|
||||
}
|
||||
|
||||
public subscribeToEtaChanges(listener: (eta: IEta) => void) {
|
||||
this.subscribers.push(listener);
|
||||
}
|
||||
|
||||
public unsubscribeFromEtaChanges(listener: (eta: IEta) => void) {
|
||||
const index = this.subscribers.findIndex((existingListener) => existingListener == listener);
|
||||
if (index >= 0) {
|
||||
this.subscribers.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public async getEtaForShuttleAndStopId(shuttleId: string, stopId: string) {
|
||||
|
||||
Reference in New Issue
Block a user