Skip to content

Commit caf5fd1

Browse files
committed
and mising utils
1 parent 99c5766 commit caf5fd1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

frameworks/keyed/jotai/src/utils.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { atom, PrimitiveAtom } from "jotai";
2+
3+
function random(max: number) {
4+
return Math.round(Math.random() * 1000) % max;
5+
}
6+
7+
const A = ["pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean", "elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable", "important", "inexpensive", "cheap", "expensive", "fancy"];
8+
const C = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"];
9+
const N = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard"];
10+
11+
let nextId = 1;
12+
13+
export interface Data {
14+
id: number;
15+
label: string;
16+
}
17+
18+
export function buildNextItem(): Data {
19+
return {
20+
id: nextId++,
21+
label: `${A[random(A.length)]} ${C[random(C.length)]} ${
22+
N[random(N.length)]
23+
}`,
24+
};
25+
}
26+
27+
export function buildDataAtoms(count: number): PrimitiveAtom<Data>[] {
28+
const data = new Array(count);
29+
for (let i = 0; i < count; i++) {
30+
data[i] = atom(buildNextItem());
31+
}
32+
return data;
33+
}

0 commit comments

Comments
 (0)