mates 0.3.2 → 0.4.0-beta.1

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.
@@ -1,29 +1,22 @@
1
1
  /**
2
- * mates — SSR mode flag
2
+ * mates — SSR mode flag + async completion tracking
3
3
  *
4
- * A simple global boolean that browser-only hooks check before doing work.
5
- * When `setSSRMode(true)` is called (by mates-ssr's renderer before rendering),
6
- * hooks like onBlur, onFocus, onResize, onInterval, etc. skip their work
7
- * entirely no event listeners, no timers, no observers.
4
+ * SSR mode flag:
5
+ * A simple global boolean that browser-only hooks check before doing work.
6
+ * When `setSSRMode(true)` is called (by mates-ssr's renderer before rendering),
7
+ * hooks like onBlur, onFocus, onResize, onInterval, etc. skip their work
8
+ * entirely — no event listeners, no timers, no observers.
8
9
  *
9
- * This is the lightest possible SSR guard: one boolean check per hook call.
10
+ * SSR async completion tracking:
11
+ * Tracks in-flight asyncAction and Fetch calls during SSR.
12
+ * When all async work completes (counter hits 0), a 5ms debounce fires
13
+ * the registered done callback so the renderer knows it's safe to serialize.
10
14
  *
11
- * Usage (inside mates-ssr renderer):
15
+ * asyncAction and Fetch call incrementSsrAsyncCounter() on start and
16
+ * decrementSsrAsyncCounter() on finish (success or error).
12
17
  *
13
- * import { setSSRMode } from "mates";
14
- *
15
- * setSSRMode(true);
16
- * // ... render components ...
17
- * setSSRMode(false);
18
- *
19
- * Usage (inside a hook):
20
- *
21
- * import { isSSR } from "../ssr/ssrFlag";
22
- *
23
- * export const onBlur = (fn) => {
24
- * if (isSSR()) return;
25
- * // ... browser-only work ...
26
- * };
18
+ * The renderer registers a callback via setSsrDoneCallback() before rendering.
19
+ * Users can also call done() explicitly to signal early completion.
27
20
  */
28
21
  /**
29
22
  * Enable or disable SSR mode.
@@ -35,4 +28,46 @@ export declare function setSSRMode(value: boolean): void;
35
28
  * Hooks should check this and bail early if true.
36
29
  */
37
30
  export declare function isSSR(): boolean;
31
+ /**
32
+ * Register the callback the renderer will invoke when all async work is done.
33
+ * Called by the renderer once per render pass, before setup runs.
34
+ * @internal
35
+ */
36
+ export declare function setSsrDoneCallback(cb: () => void): void;
37
+ /**
38
+ * Increment the in-flight counter.
39
+ * Called by asyncAction and Fetch when they start an async operation during SSR.
40
+ * @internal
41
+ */
42
+ export declare function incrementSsrAsyncCounter(): void;
43
+ /**
44
+ * Decrement the in-flight counter.
45
+ * Called by asyncAction and Fetch when they finish (success or error).
46
+ * When counter hits 0, schedules the done callback with a 5ms debounce.
47
+ * @internal
48
+ */
49
+ export declare function decrementSsrAsyncCounter(): void;
50
+ /**
51
+ * Explicitly signal that the component is done with all async work.
52
+ * Call this if you have async work that happens outside asyncAction/Fetch
53
+ * and the renderer should not wait longer.
54
+ *
55
+ * @example
56
+ * export default (_: Props<{}>) => {
57
+ * const data = asyncAction(fetchData);
58
+ * data();
59
+ *
60
+ * // If you have additional async work tracked manually:
61
+ * done();
62
+ *
63
+ * return () => html`...`;
64
+ * };
65
+ */
66
+ export declare function done(): void;
67
+ /**
68
+ * Returns the current number of in-flight SSR async operations.
69
+ * Useful for debugging and tests.
70
+ */
71
+ export declare function getSsrAsyncCounter(): number;
72
+ export declare function isDev(): boolean;
38
73
  //# sourceMappingURL=ssrFlag.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssrFlag.d.ts","sourceRoot":"","sources":["../../lib/ssr/ssrFlag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAE/C;AAED;;;GAGG;AACH,wBAAgB,KAAK,IAAI,OAAO,CAE/B"}
1
+ {"version":3,"file":"ssrFlag.d.ts","sourceRoot":"","sources":["../../lib/ssr/ssrFlag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAMH;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAQ/C;AAED;;;GAGG;AACH,wBAAgB,KAAK,IAAI,OAAO,CAE/B;AAgBD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAOvD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAQ/C;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAI/C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,IAAI,IAAI,CAS3B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAqBD,wBAAgB,KAAK,IAAI,OAAO,CAQ/B"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "mates",
3
- "version": "0.3.2",
3
+ "version": "0.4.0-beta.1",
4
4
  "type": "module",
5
5
  "description": "Mates is a front end framework for building web applications",
6
- "main": "dist/index.esm.js",
6
+ "main": "dist/index.js",
7
7
  "module": "dist/index.esm.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "exports": {