mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-17 10:21:03 +00:00
Don't sort the list on every render (#58)
This commit is contained in:
@@ -35,8 +35,26 @@ export interface State {
|
||||
subscribed: Maybe<Types.ChainLabel>;
|
||||
chains: Map<Types.ChainLabel, Types.NodeCount>;
|
||||
nodes: Map<Types.NodeId, State.Node>;
|
||||
sortedNodes: State.Node[];
|
||||
settings: Readonly<State.Settings>;
|
||||
pins: Readonly<Set<Types.NodeName>>;
|
||||
}
|
||||
|
||||
export type Update = <K extends keyof State>(changes: Pick<State, K> | null) => Readonly<State>;
|
||||
|
||||
export function compareNodes(a: State.Node, b: State.Node): number {
|
||||
if (a.pinned === b.pinned) {
|
||||
if (a.blockDetails[0] === b.blockDetails[0]) {
|
||||
const aPropagation = a.blockDetails[4] == null ? Infinity : a.blockDetails[4] as number;
|
||||
const bPropagation = b.blockDetails[4] == null ? Infinity : b.blockDetails[4] as number;
|
||||
|
||||
// Ascending sort by propagation time
|
||||
return aPropagation - bPropagation;
|
||||
}
|
||||
} else {
|
||||
return +b.pinned - +a.pinned;
|
||||
}
|
||||
|
||||
// Descending sort by block number
|
||||
return b.blockDetails[0] - a.blockDetails[0];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user