@xynogen/pix-todo 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/once.ts +2 -1
- package/src/todo.test.ts +11 -6
package/package.json
CHANGED
package/src/once.ts
CHANGED
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
*/
|
|
15
15
|
export function once(pi: object, key: string, fn: () => void): void {
|
|
16
16
|
const g = globalThis as { __pixOnce?: WeakMap<object, Set<string>> };
|
|
17
|
-
|
|
17
|
+
if (!g.__pixOnce) g.__pixOnce = new WeakMap<object, Set<string>>();
|
|
18
|
+
const registry = g.__pixOnce;
|
|
18
19
|
let loaded = registry.get(pi);
|
|
19
20
|
if (!loaded) {
|
|
20
21
|
loaded = new Set<string>();
|
package/src/todo.test.ts
CHANGED
|
@@ -67,7 +67,8 @@ function makeHost(
|
|
|
67
67
|
appendCalls.push({ type, data });
|
|
68
68
|
},
|
|
69
69
|
on(ev: string, fn: (event: unknown, ctx?: unknown) => unknown) {
|
|
70
|
-
(handlers[ev]
|
|
70
|
+
if (!handlers[ev]) handlers[ev] = [];
|
|
71
|
+
handlers[ev].push(fn);
|
|
71
72
|
},
|
|
72
73
|
async emit(ev: string, event?: unknown, ctx?: unknown) {
|
|
73
74
|
for (const fn of handlers[ev] ?? []) await fn(event, ctx);
|
|
@@ -84,10 +85,12 @@ function makeHost(
|
|
|
84
85
|
pi,
|
|
85
86
|
sessionManager,
|
|
86
87
|
get execute() {
|
|
87
|
-
|
|
88
|
+
if (!capturedExecute) throw new Error("execute not captured");
|
|
89
|
+
return capturedExecute;
|
|
88
90
|
},
|
|
89
91
|
get render() {
|
|
90
|
-
|
|
92
|
+
if (!capturedRender) throw new Error("render not captured");
|
|
93
|
+
return capturedRender;
|
|
91
94
|
},
|
|
92
95
|
appendCalls,
|
|
93
96
|
async emit(ev: string, event?: unknown, ctx?: unknown) {
|
|
@@ -501,6 +504,7 @@ describe("todo actions", () => {
|
|
|
501
504
|
// ─── Persistence ────────────────────────────────────────────────────────────
|
|
502
505
|
|
|
503
506
|
describe("persistence", () => {
|
|
507
|
+
type AppendCall = { type: string; data: unknown };
|
|
504
508
|
test("set persists todos", async () => {
|
|
505
509
|
const host = makeHost();
|
|
506
510
|
registerTodo(host.pi);
|
|
@@ -512,8 +516,9 @@ describe("persistence", () => {
|
|
|
512
516
|
host.appendCalls.length = 0;
|
|
513
517
|
await run(host.execute, { action: "set", items: "alpha\nbravo" });
|
|
514
518
|
expect(host.appendCalls.length).toBe(1);
|
|
515
|
-
|
|
516
|
-
|
|
519
|
+
const ac0 = host.appendCalls[0] as AppendCall;
|
|
520
|
+
expect(ac0.type).toBe("todo-state");
|
|
521
|
+
const data = ac0.data as {
|
|
517
522
|
todos: Array<{ id: number; text: string; status: string }>;
|
|
518
523
|
nextTodoId: number;
|
|
519
524
|
};
|
|
@@ -561,7 +566,7 @@ describe("persistence", () => {
|
|
|
561
566
|
host.appendCalls.length = 0;
|
|
562
567
|
await run(host.execute, { action: "clear" });
|
|
563
568
|
expect(host.appendCalls.length).toBe(1);
|
|
564
|
-
const data = host.appendCalls[0].data as {
|
|
569
|
+
const data = (host.appendCalls[0] as AppendCall).data as {
|
|
565
570
|
todos: Array<unknown>;
|
|
566
571
|
nextTodoId: number;
|
|
567
572
|
};
|