mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
rename methods for clarity on method events
This commit is contained in:
@@ -25,7 +25,7 @@ export interface GetterRepository {
|
|||||||
* if ETA data is restored.
|
* if ETA data is restored.
|
||||||
* @param listener
|
* @param listener
|
||||||
*/
|
*/
|
||||||
subscribeToEtaChanges(
|
subscribeToEtaUpdates(
|
||||||
listener: (eta: IEta) => void,
|
listener: (eta: IEta) => void,
|
||||||
): void;
|
): void;
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ export interface GetterRepository {
|
|||||||
* Callback must be passed by reference.
|
* Callback must be passed by reference.
|
||||||
* @param listener
|
* @param listener
|
||||||
*/
|
*/
|
||||||
unsubscribeFromEtaChanges(listener: (eta: IEta) => void): void;
|
unsubscribeFromEtaUpdates(listener: (eta: IEta) => void): void;
|
||||||
|
|
||||||
getOrderedStopByRouteAndStopId(routeId: string, stopId: string): Promise<IOrderedStop | null>;
|
getOrderedStopByRouteAndStopId(routeId: string, stopId: string): Promise<IOrderedStop | null>;
|
||||||
|
|
||||||
|
|||||||
@@ -61,11 +61,11 @@ export class UnoptimizedInMemoryRepository implements GetterSetterRepository {
|
|||||||
return this.etas.filter(eta => eta.stopId === stopId);
|
return this.etas.filter(eta => eta.stopId === stopId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public subscribeToEtaChanges(listener: (eta: IEta) => void) {
|
public subscribeToEtaUpdates(listener: (eta: IEta) => void) {
|
||||||
this.subscribers.push(listener);
|
this.subscribers.push(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsubscribeFromEtaChanges(listener: (eta: IEta) => void) {
|
public unsubscribeFromEtaUpdates(listener: (eta: IEta) => void) {
|
||||||
const index = this.subscribers.findIndex((existingListener) => existingListener == listener);
|
const index = this.subscribers.findIndex((existingListener) => existingListener == listener);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
this.subscribers.splice(index, 1);
|
this.subscribers.splice(index, 1);
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
describe("subscribeToEtaChanges", () => {
|
describe("subscribeToEtaChanges", () => {
|
||||||
test("notifies listeners if etas have been added or changed", async () => {
|
test("notifies listeners if etas have been added or changed", async () => {
|
||||||
const mockCallback = jest.fn(); // Jest mock function to simulate a listener
|
const mockCallback = jest.fn(); // Jest mock function to simulate a listener
|
||||||
repository.subscribeToEtaChanges(mockCallback);
|
repository.subscribeToEtaUpdates(mockCallback);
|
||||||
|
|
||||||
const mockEtas = generateMockEtas();
|
const mockEtas = generateMockEtas();
|
||||||
for (const eta of mockEtas) {
|
for (const eta of mockEtas) {
|
||||||
@@ -244,12 +244,12 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
describe("unsubscribeFromEtaChanges", () => {
|
describe("unsubscribeFromEtaChanges", () => {
|
||||||
test("stops notifying listeners after etas have stopped changing", async () => {
|
test("stops notifying listeners after etas have stopped changing", async () => {
|
||||||
const mockCallback = jest.fn(); // Jest mock function to simulate a listener
|
const mockCallback = jest.fn(); // Jest mock function to simulate a listener
|
||||||
repository.subscribeToEtaChanges(mockCallback);
|
repository.subscribeToEtaUpdates(mockCallback);
|
||||||
|
|
||||||
const mockEtas = generateMockEtas();
|
const mockEtas = generateMockEtas();
|
||||||
await repository.addOrUpdateEta(mockEtas[0]);
|
await repository.addOrUpdateEta(mockEtas[0]);
|
||||||
|
|
||||||
repository.unsubscribeFromEtaChanges(mockCallback);
|
repository.unsubscribeFromEtaUpdates(mockCallback);
|
||||||
|
|
||||||
await repository.addOrUpdateEta(mockEtas[mockEtas.length - 1]);
|
await repository.addOrUpdateEta(mockEtas[mockEtas.length - 1]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user