Sort buffers when inserting, not when rendering

This allows all state.buffers users to iterate over the list in the
correct order.
This commit is contained in:
Simon Ser 2020-08-03 15:43:20 +02:00
parent ee8b40aae4
commit 6c93bd13d1
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 23 additions and 20 deletions

View file

@ -26,28 +26,11 @@ function BufferItem(props) {
`;
}
function compareBuffers(a, b) {
if (a.type == BufferType.SERVER) {
return -1;
}
if (b.type == BufferType.SERVER) {
return 1;
}
if (a.name > b.name) {
return -1;
}
if (a.name < b.name) {
return 1;
}
return 0;
}
export default function BufferList(props) {
return html`
<ul>
${Array.from(props.buffers.values()).sort(compareBuffers).map(buf => html`
${Array.from(props.buffers.values()).map((buf) => html`
<${BufferItem} key=${buf.name} buffer=${buf} onClick=${() => props.onBufferClick(buf.name)} active=${props.activeBuffer == buf.name}/>
`)}
</ul>