@xynogen/pix-todo 0.1.2 → 0.1.4
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/README.md +2 -0
- package/package.json +1 -1
- package/src/once.ts +19 -9
- package/src/todo.test.ts +5 -5
- package/src/todo.ts +1 -1
package/README.md
CHANGED
package/package.json
CHANGED
package/src/once.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Per-instance idempotency guard for extension activation.
|
|
3
3
|
*
|
|
4
|
-
* pix-core (the meta-package) invokes this package's factory
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* pix-core (the meta-package) invokes this package's factory, and a standalone
|
|
5
|
+
* install makes Pi invoke it again — sometimes against the SAME `pi`. We must
|
|
6
|
+
* dedupe that. But Pi rebuilds the extension runtime on /new, /resume, /fork,
|
|
7
|
+
* and /reload, handing the factory a BRAND-NEW `pi`; that must re-register.
|
|
8
|
+
*
|
|
9
|
+
* Keying the registry on the `pi` instance satisfies both: same instance =>
|
|
10
|
+
* skip, new instance => run. The registry lives on globalThis because jiti
|
|
11
|
+
* (`moduleCache: false`) re-evaluates this module on every load pass, so a
|
|
12
|
+
* module-scoped WeakMap would not be shared between the aggregator pass and the
|
|
13
|
+
* standalone pass within a single session.
|
|
9
14
|
*/
|
|
10
|
-
export function once(key: string, fn: () => void): void {
|
|
11
|
-
const g = globalThis as {
|
|
12
|
-
const
|
|
15
|
+
export function once(pi: object, key: string, fn: () => void): void {
|
|
16
|
+
const g = globalThis as { __pixOnce?: WeakMap<object, Set<string>> };
|
|
17
|
+
const registry = (g.__pixOnce ??= new WeakMap<object, Set<string>>());
|
|
18
|
+
let loaded = registry.get(pi);
|
|
19
|
+
if (!loaded) {
|
|
20
|
+
loaded = new Set<string>();
|
|
21
|
+
registry.set(pi, loaded);
|
|
22
|
+
}
|
|
13
23
|
if (loaded.has(key)) return;
|
|
14
24
|
loaded.add(key);
|
|
15
25
|
fn();
|
package/src/todo.test.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, test } from "bun:test";
|
|
2
2
|
import registerTodo, { renderTodoLines, type TodoItem } from "./todo.ts";
|
|
3
3
|
|
|
4
|
-
// registerTodo wraps its body in once("pix-todo") — a
|
|
5
|
-
// guard that dedupes activation across pix-core + a standalone install.
|
|
6
|
-
// re-register a fresh host per case
|
|
7
|
-
//
|
|
4
|
+
// registerTodo wraps its body in once(pi, "pix-todo") — a per-instance
|
|
5
|
+
// WeakMap guard that dedupes activation across pix-core + a standalone install.
|
|
6
|
+
// Tests re-register a fresh host per case. Clear the registry between tests so
|
|
7
|
+
// that the same pi object can be re-used without cross-test interference.
|
|
8
8
|
beforeEach(() => {
|
|
9
|
-
delete (globalThis as {
|
|
9
|
+
delete (globalThis as { __pixOnce?: WeakMap<object, Set<string>> }).__pixOnce;
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
// Stub theme tags each fragment with its color/bold so assertions can verify
|
package/src/todo.ts
CHANGED