Lint stuff

This commit is contained in:
Gregory Schier
2026-03-08 15:50:13 -07:00
parent 96a22c68f2
commit 6e11894f79
4 changed files with 35 additions and 20 deletions
-3
View File
@@ -5,8 +5,6 @@
"useDefineForClassFields": true, "useDefineForClassFields": true,
"allowJs": false, "allowJs": false,
"skipLibCheck": true, "skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true, "strict": true,
"noUncheckedIndexedAccess": true, "noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
@@ -16,7 +14,6 @@
"isolatedModules": true, "isolatedModules": true,
"noEmit": true, "noEmit": true,
"jsx": "react-jsx", "jsx": "react-jsx",
"baseUrl": ".",
"paths": { "paths": {
"@yaakapp-internal/theme": ["../../packages/theme/src/index.ts"], "@yaakapp-internal/theme": ["../../packages/theme/src/index.ts"],
"@yaakapp-internal/theme/*": ["../../packages/theme/src/*"], "@yaakapp-internal/theme/*": ["../../packages/theme/src/*"],
+3 -1
View File
@@ -22,7 +22,9 @@ export function listen<K extends keyof RpcEventSchema>(
): () => void { ): () => void {
let unsub: (() => void) | null = null; let unsub: (() => void) | null = null;
tauriListen<RpcEventSchema[K]>(event, (e) => callback(e.payload)) tauriListen<RpcEventSchema[K]>(event, (e) => callback(e.payload))
.then((fn) => (unsub = fn)) .then((fn) => {
unsub = fn;
})
.catch(console.error); .catch(console.error);
return () => unsub?.(); return () => unsub?.();
} }
+5 -1
View File
@@ -1,8 +1,12 @@
import { createModelStore } from "@yaakapp-internal/model-store"; import { createModelStore } from "@yaakapp-internal/model-store";
import type { HttpExchange } from "../../crates-proxy/yaak-proxy-lib/bindings/gen_models"; import type { HttpExchange } from "../../crates-proxy/yaak-proxy-lib/bindings/gen_models";
type ProxyModels = {
http_exchange: HttpExchange;
};
export const { dataAtom, applyChange, listAtom, orderedListAtom } = export const { dataAtom, applyChange, listAtom, orderedListAtom } =
createModelStore<HttpExchange>(); createModelStore<ProxyModels>(["http_exchange"]);
export const httpExchangesAtom = orderedListAtom( export const httpExchangesAtom = orderedListAtom(
"http_exchange", "http_exchange",
+27 -15
View File
@@ -1,22 +1,34 @@
import { atom } from "jotai"; import { atom } from "jotai";
import { selectAtom } from "jotai/utils"; import { selectAtom } from "jotai/utils";
/** Any model must at least have an id. */ /** Model map: each key is a model type name, each value is the model shape (must have id). */
type BaseModel = { id: string }; type ModelMap = Record<string, { id: string }>;
/** The raw store shape: model type string → id → model instance. */ /** The store data shape derived from the model map. */
type StoreData<M extends BaseModel> = Record<string, Record<string, M>>; type StoreData<M extends ModelMap> = {
[K in keyof M]: Record<string, M[K]>;
};
export type ModelChange = { type: "upsert" } | { type: "delete" }; export type ModelChange = { type: "upsert" } | { type: "delete" };
export function createModelStore<M extends BaseModel>() { function emptyStore<M extends ModelMap>(keys: (keyof M)[]): StoreData<M> {
const dataAtom = atom<StoreData<M>>({}); const data = {} as StoreData<M>;
for (const k of keys) {
data[k] = {} as Record<string, M[typeof k]>;
}
return data;
}
export function createModelStore<M extends ModelMap>(
modelTypes: (keyof M & string)[],
) {
const dataAtom = atom<StoreData<M>>(emptyStore<M>(modelTypes));
/** Apply a single upsert or delete to the store. */ /** Apply a single upsert or delete to the store. */
function applyChange( function applyChange<K extends keyof M & string>(
prev: StoreData<M>, prev: StoreData<M>,
modelType: string, modelType: K,
model: M, model: M[K],
change: ModelChange, change: ModelChange,
): StoreData<M> { ): StoreData<M> {
if (change.type === "upsert") { if (change.type === "upsert") {
@@ -32,24 +44,24 @@ export function createModelStore<M extends BaseModel>() {
} }
/** Atom that selects all models of a given type as an array. */ /** Atom that selects all models of a given type as an array. */
function listAtom(modelType: string) { function listAtom<K extends keyof M & string>(modelType: K) {
return selectAtom( return selectAtom(
dataAtom, dataAtom,
(data) => Object.values(data[modelType] ?? {}), (data) => Object.values(data[modelType] ?? {}) as M[K][],
shallowEqual, shallowEqual,
); );
} }
/** Atom that selects all models of a given type, sorted by a field. */ /** Atom that selects all models of a given type, sorted by a field. */
function orderedListAtom<K extends keyof M>( function orderedListAtom<K extends keyof M & string>(
modelType: string, modelType: K,
field: K, field: keyof M[K],
order: "asc" | "desc", order: "asc" | "desc",
) { ) {
return selectAtom( return selectAtom(
dataAtom, dataAtom,
(data) => { (data) => {
const vals = Object.values(data[modelType] ?? {}); const vals = Object.values(data[modelType] ?? {}) as M[K][];
return vals.sort((a, b) => { return vals.sort((a, b) => {
const n = a[field] > b[field] ? 1 : -1; const n = a[field] > b[field] ? 1 : -1;
return order === "desc" ? -n : n; return order === "desc" ? -n : n;