History Manager v1.0.60¶
singleton
Global singleton that records the full ILocus snapshot of every locus the user has visited (including mode / DNA window / RNA identity / assembly). Keeps at most the 20 most recent entries (the MAX_HISTORY constant). Completely independent of favouriteManager.
Switched to ILocus storage since v1.0.50
Older versions (≤ v1.0.49) stored a bare region string plus assembly metadata. The new version stores the full ILocus, and the attached mode field lets users distinguish the RNA / DNA / CDS ways of opening the same gene within the history.
Legacy entries in localStorage (key tbrowser_history_v1) are migrated automatically on load (string → ILocus, timestamp → ISO string), so users' bookmarks are never lost.
API aligned with favouriteManager
Since v1.0.51, historyManager's method names, signatures, and event shapes match favouriteManager—on / has / hasKey / getAll / count / remove (returns boolean) / removeKey / clear—so callers can treat both managers as the same interface. The only thing missing is toggle() ("visited" has no toggle semantics), and add() returns void.
Method¶
add¶
method
Records a visit and returns void. An existing entry with the same key (the mode-aware identity of ILocus) is removed first and re-inserted at the front—so visiting the same identity multiple times leaves only the latest entry. Once there are more than MAX_HISTORY (20) entries, the oldest is discarded automatically.
| Parameter | Type | Required | Description |
|---|---|---|---|
locus |
ILocus |
✓ | Usually pass the return value of renderer.locusManager.getLocus() directly |
Why ILocus instead of a string
ILocus carries its own mode / assembly / time / id, far more complete than "a region string plus an assembly argument alongside it." The current position can always be fetched on demand via renderer.locusManager.getLocus().
has / hasKey¶
method
historyManager.hasKey(key: string): boolean
Checks whether the same record already exists in the history by its mode-aware identity key. Use hasKey() when you already have the key string—it saves a computation.
getAll¶
method
Returns the entire history in reverse chronological order (newest first). It is already capped internally to 20 entries by MAX_HISTORY, so you can render it directly.
historyManager.getAll().forEach((locus) => {
console.log(
`[${locus.mode.toUpperCase()}]`,
locus.dna.chr ? `${locus.dna.chr}:${locus.dna.start}-${locus.dna.end}` : locus.rna.trans_name,
`@`, locus.dna.assembly || locus.rna.assembly,
`(${locus.time})`,
);
});
count¶
getter
The current number of history entries (at most MAX_HISTORY = 20).
remove / removeKey¶
method
historyManager.removeKey(key: string): boolean
Removes by identity key and returns whether an entry was actually removed. Use removeKey() when you already have the key to save a computation.
clear¶
method
Clears all history (does not affect favourites).
on¶
method
Subscribes to history events and returns an unsubscribe function.
const unsubscribe = historyManager.on((event, detail) => {
switch (event) {
case "add":
case "remove":
console.log(event, detail?.key);
// detail.locus is the full ILocus snapshot
break;
case "clear":
console.log("History cleared");
break;
}
});
unsubscribe();
Event¶
event
| Event | Trigger | detail fields |
|---|---|---|
"add" |
Every add() (including same-key replacement) |
locus, key |
"remove" |
remove() / removeKey() actually removed an entry |
locus, key |
"clear" |
clear() is called |
—— |
HistoryEvent / HistoryListener¶
type
type HistoryEvent = "add" | "remove" | "clear";
type HistoryListener = (
event: HistoryEvent,
detail?: {
locus?: ILocus;
key?: string;
},
) => void;