-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4366076
commit d25a5bc
Showing
2 changed files
with
22 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,39 @@ | ||
import {random_id, UUID} from "./tree"; | ||
|
||
export interface Marker { | ||
id(): UUID; | ||
|
||
withId(id: UUID): Marker; | ||
} | ||
|
||
export class Markers { | ||
public static readonly EMPTY: Markers = new Markers(random_id(), []); | ||
|
||
private readonly _id: string; | ||
private readonly _id: UUID; | ||
private readonly _markers: Marker[] = []; | ||
|
||
constructor(id: UUID, markers: Marker[]) { | ||
this._id = id; | ||
this._markers = markers; | ||
} | ||
|
||
public id(): string { | ||
public id(): UUID { | ||
return this._id; | ||
} | ||
|
||
public withId(id: UUID): Markers { | ||
return this._id === id ? this : new Markers(id, this._markers); | ||
} | ||
|
||
public markers(): Marker[] { | ||
return this._markers; | ||
} | ||
|
||
public findFirst<T extends Marker>(markerType: new () => T): T | null { | ||
return this._markers.find((marker) => marker instanceof markerType) as T || null; | ||
public withMarkers(markers: Marker[]): Markers { | ||
return this._markers === markers ? this : new Markers(this._id, markers); | ||
} | ||
|
||
public findFirst<T extends Marker>(markerType: new () => T): T | undefined { | ||
return this._markers.find((marker) => marker instanceof markerType) as T || undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters