foldkit 0.10.0-canary.3 → 0.10.0-canary.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.
@@ -48,13 +48,13 @@ const makeRuntime = ({ Model, init, update, view, commandStreams, container, bro
48
48
  const message = yield* Queue.take(messageQueue);
49
49
  const currentModel = yield* Ref.get(modelRef);
50
50
  const [nextModel, commands] = update(currentModel, message);
51
- yield* Effect.forEach(commands, (command) => Effect.forkDaemon(command.pipe(Effect.flatMap(enqueueMessage))));
52
51
  if (!modelEquivalence(currentModel, nextModel)) {
53
52
  yield* Ref.set(modelRef, nextModel);
54
53
  yield* render(nextModel);
55
54
  yield* SubscriptionRef.set(modelSubscriptionRef, nextModel);
56
55
  preserveModel(nextModel);
57
56
  }
57
+ yield* Effect.forEach(commands, (command) => Effect.forkDaemon(command.pipe(Effect.flatMap(enqueueMessage))));
58
58
  }));
59
59
  });
60
60
  const patchVNode = (maybeCurrentVNode, nextVNodeNullish, container) => {
package/dist/task.d.ts CHANGED
@@ -42,6 +42,8 @@ export declare const getZonedTimeIn: <Message>(zoneId: string, f: (zoned: DateTi
42
42
  /**
43
43
  * Creates a command that focuses an element by selector and passes the result to a message constructor.
44
44
  * Returns true if the element was found and focused, false otherwise.
45
+ * Uses requestAnimationFrame to ensure the DOM tree is updated and nodes exist before attempting to focus.
46
+ * This follows the same approach as Elm's Browser.Dom.focus.
45
47
  *
46
48
  * @example
47
49
  * ```typescript
@@ -1 +1 @@
1
- {"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../src/task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAEjD;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,EAAE,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,KAAK,OAAO,KAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAC7D,CAAA;AAE7B;;;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AI,OAAO,EACjC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,KAAK,OAAO,KACtC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAmD,CAAA;AAE3E;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,EAClC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,KAAK,OAAO,KACpC,MAAM,CAAC,MAAM,CAAC,OAAO,CAMpB,CAAA;AAEJ;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,EACpC,QAAQ,MAAM,EACd,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,KAAK,OAAO,KACpC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAS5B,CAAA;AAEJ;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GAAI,OAAO,EAC3B,UAAU,MAAM,EAChB,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,KAC/B,MAAM,CAAC,MAAM,CAAC,OAAO,CAWpB,CAAA;AAEJ;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,EAC/B,KAAK,MAAM,EACX,KAAK,MAAM,EACX,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,KAC5B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAwE,CAAA"}
package/dist/task.js CHANGED
@@ -55,19 +55,25 @@ export const getZonedTimeIn = (zoneId, f) => Effect.gen(function* () {
55
55
  /**
56
56
  * Creates a command that focuses an element by selector and passes the result to a message constructor.
57
57
  * Returns true if the element was found and focused, false otherwise.
58
+ * Uses requestAnimationFrame to ensure the DOM tree is updated and nodes exist before attempting to focus.
59
+ * This follows the same approach as Elm's Browser.Dom.focus.
58
60
  *
59
61
  * @example
60
62
  * ```typescript
61
63
  * Task.focus('#email-input', success => InputFocused.make({ success }))
62
64
  * ```
63
65
  */
64
- export const focus = (selector, f) => Effect.sync(() => {
65
- const element = document.querySelector(selector);
66
- if (element instanceof HTMLElement) {
67
- element.focus();
68
- return f(true);
69
- }
70
- return f(false);
66
+ export const focus = (selector, f) => Effect.async((resume) => {
67
+ requestAnimationFrame(() => {
68
+ const element = document.querySelector(selector);
69
+ if (element instanceof HTMLElement) {
70
+ element.focus();
71
+ resume(Effect.succeed(f(true)));
72
+ }
73
+ else {
74
+ resume(Effect.succeed(f(false)));
75
+ }
76
+ });
71
77
  });
72
78
  /**
73
79
  * Creates a command that generates a random integer between min (inclusive) and max (exclusive)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldkit",
3
- "version": "0.10.0-canary.3",
3
+ "version": "0.10.0-canary.4",
4
4
  "description": "Elm-inspired UI framework powered by Effect",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",