mirror of
https://github.com/outline/outline.git
synced 2026-11-26 23:50:14 +03:00
* refactor: DRY up app stores with fetchPaginated helper and IndexedStore Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * refactor: Resolve related models by store responseKey instead of a key map Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
23 lines
584 B
TypeScript
23 lines
584 B
TypeScript
import { override } from "mobx";
|
|
import type Model from "~/models/base/Model";
|
|
import Store from "./Store";
|
|
|
|
/**
|
|
* A store for models that carry a fractional index, ordered by that index and
|
|
* then by the most recently updated.
|
|
*/
|
|
export default abstract class IndexedStore<
|
|
T extends Model & { index: string },
|
|
> extends Store<T> {
|
|
@override
|
|
get orderedData(): T[] {
|
|
return Array.from(this.data.values()).sort((a, b) => {
|
|
if (a.index === b.index) {
|
|
return a.updatedAt > b.updatedAt ? -1 : 1;
|
|
}
|
|
|
|
return a.index < b.index ? -1 : 1;
|
|
});
|
|
}
|
|
}
|