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:
parent
ee8b40aae4
commit
6c93bd13d1
2 changed files with 23 additions and 20 deletions
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue