ilha 0.14.3 → 0.14.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 CHANGED
@@ -55,7 +55,9 @@ import * as Atom from "effect/unstable/reactivity/Atom";
55
55
  import { atom } from "ilha";
56
56
 
57
57
  const items = atom([{ n: 1 }, { n: 2 }]);
58
- const total = atom(Atom.map(items.atom, (list) => list.reduce((sum, item) => sum + item.n, 0)));
58
+ const total = atom(
59
+ Atom.map(items.atom, (list) => list.reduce((sum, item) => sum + item.n, 0))
60
+ );
59
61
  ```
60
62
 
61
63
  Wrap multiple writes in `batch()`. Derived and mutation atoms use Effect's `Atom.map`, `Atom.transform`, and `Atom.fn` — pass `handle.atom`, then wrap in `atom()`. Use `watch(source, fn)` for side effects on atom changes.
package/dist/define.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { n as Component } from "./types-Cie0Ihl6.js";
1
+ import { n as Component } from "./types-DQVTD0ts.js";
2
2
  //#region src/define.d.ts
3
- declare function define(name: string, component: Component): void;
3
+ declare const define: (name: string, component: Component) => void;
4
4
  //#endregion
5
5
  export { define };
package/dist/define.js CHANGED
@@ -1,18 +1,18 @@
1
- import { t as mount } from "./mount-CCMOkDSb.js";
1
+ import { t as mount } from "./mount-hD-OyLIo.js";
2
2
 
3
3
  //#region src/define.ts
4
- function define(name, component) {
4
+ const define = (name, component) => {
5
5
  customElements.define(name, class extends HTMLElement {
6
6
  #unmount;
7
7
  connectedCallback() {
8
- this.#unmount = mount(this, component, { hydrate: this.hasAttribute("data-ilha") });
8
+ this.#unmount = mount(this, component, { hydrate: this.matches("[data-ilha]") });
9
9
  }
10
10
  disconnectedCallback() {
11
11
  this.#unmount?.();
12
12
  this.#unmount = void 0;
13
13
  }
14
14
  });
15
- }
15
+ };
16
16
 
17
17
  //#endregion
18
18
  export { define };
package/dist/index.d.ts CHANGED
@@ -1,37 +1,42 @@
1
- import { i as Instruction, n as Component, o as View, r as Fragment, s as Yielded, t as AtomHandle } from "./types-Cie0Ihl6.js";
2
- import { t as h } from "./vnode-15tImQ6O.js";
1
+ import { a as Instruction, c as View, i as Fragment, l as Yielded, n as Component, t as AtomHandle } from "./types-DQVTD0ts.js";
2
+ import { t as h } from "./vnode-DHBqDHtZ.js";
3
3
  import * as Effect from "effect/Effect";
4
4
  import * as Stream from "effect/Stream";
5
5
  import * as Atom from "effect/unstable/reactivity/Atom";
6
6
  import "effect/Scope";
7
7
  import { AtomRegistry } from "effect/unstable/reactivity/AtomRegistry";
8
8
  //#region src/watch.d.ts
9
+ /** Values delivered to watch callbacks. */
10
+ type WatchValue = string | number | boolean | bigint | null | undefined | readonly WatchValue[] | WatchRecord;
11
+ interface WatchRecord {
12
+ readonly [key: string]: WatchValue | undefined;
13
+ }
9
14
  /** Run `fn` when `source` changes — and once on mount. Sync, async, and generator components. */
10
- declare function watch<A>(source: AtomHandle<A> | Atom.Atom<A> | Stream.Stream<A, any, any>, fn: (value: A) => void): Instruction<void>;
15
+ declare const watch: <A extends WatchValue>(source: AtomHandle<A> | Atom.Atom<A> | Stream.Stream<A, unknown, unknown>, fn: (value: A) => void) => Instruction<undefined>;
11
16
  //#endregion
12
17
  //#region src/atom.d.ts
13
18
  interface AtomFn {
14
- <A>(init: A | Atom.Atom<A> | Effect.Effect<A, any, any> | Stream.Stream<A, any, any>): AtomHandle<A>;
15
- lazy<A>(init: () => A): AtomHandle<A>;
19
+ <A>(init: A | Atom.Atom<A> | Effect.Effect<A, unknown, AtomRegistry> | Stream.Stream<A, unknown, AtomRegistry>): AtomHandle<A>;
20
+ lazy: <A>(init: () => A) => AtomHandle<A>;
16
21
  }
17
22
  declare const atom: AtomFn;
18
23
  declare const batch: (f: () => void) => void;
19
24
  //#endregion
20
25
  //#region src/when.d.ts
21
- declare function when<A, E = never, R = never>(stream: Stream.Stream<A, E, R>, body: (value: A) => Generator<Yielded, View | void, unknown>): Instruction<void, E>;
26
+ declare const when: <A, E = never, R = never>(stream: Stream.Stream<A, E, R>, body: (value: A) => Generator<Yielded, View | undefined, View>) => Instruction<undefined, E>;
22
27
  //#endregion
23
28
  //#region src/mount.d.ts
24
- type RenderToStringOptions = {
29
+ interface RenderToStringOptions {
25
30
  snapshot?: boolean;
26
31
  markers?: boolean;
27
32
  timeout?: number;
28
33
  captureActions?: boolean;
29
- };
30
- type MountOptions = {
34
+ }
35
+ interface MountOptions {
31
36
  hydrate?: boolean;
32
- onError?: (error: unknown) => void;
33
- };
34
- declare function mount(el: Element, fn: Component, opts?: MountOptions): () => void;
35
- declare function renderToString(fn: Component, opts?: RenderToStringOptions): Promise<string>;
37
+ onError?: <E>(error: E) => void;
38
+ }
39
+ declare const mount: (el: Element, fn: Component, opts?: MountOptions) => (() => void);
40
+ declare const renderToString: (fn: Component, opts?: RenderToStringOptions) => Promise<string>;
36
41
  //#endregion
37
42
  export { type AtomHandle, type Component, Fragment, type MountOptions, type RenderToStringOptions, type View, atom, batch, h, mount, renderToString, watch, when };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { a as atom, c as instr, d as getFiber, f as makeFiber, i as interpret, l as isAtomHandle, n as renderToString, o as batch, r as paint, s as handleOwner, t as mount, u as closeFiber } from "./mount-CCMOkDSb.js";
2
- import { i as Fragment, t as h } from "./vnode-DHN2EFHi.js";
1
+ import { a as batch, c as isAtomHandle, d as makeFiber, i as atom, l as closeFiber, n as renderToString, o as handleOwner, r as interpret, s as instr, t as mount, u as getFiber } from "./mount-hD-OyLIo.js";
2
+ import { i as Fragment, t as h } from "./vnode-DP76Gn-b.js";
3
3
  import * as Effect from "effect/Effect";
4
4
  import * as Stream from "effect/Stream";
5
5
  import * as Exit from "effect/Exit";
@@ -8,7 +8,7 @@ import * as Scope from "effect/Scope";
8
8
  import * as Registry from "effect/unstable/reactivity/AtomRegistry";
9
9
 
10
10
  //#region src/watch.ts
11
- function runStreamWatch(fiber, effect) {
11
+ const runStreamWatch = (fiber, effect) => {
12
12
  const scope = Scope.forkUnsafe(fiber.scope);
13
13
  const provided = effect.pipe(Effect.provideService(Registry.AtomRegistry, fiber.registry));
14
14
  const fork = Effect.runFork(provided);
@@ -16,31 +16,32 @@ function runStreamWatch(fiber, effect) {
16
16
  return () => {
17
17
  Effect.runFork(Scope.close(scope, Exit.void));
18
18
  };
19
- }
20
- function useWatchSlot(fiber, key, mount, fn) {
19
+ };
20
+ const useWatchSlot = (fiber, key, mount, fn) => {
21
21
  const i = fiber.watchI ?? 0;
22
22
  fiber.watchI = i + 1;
23
23
  fiber.watchSlots ??= [];
24
24
  const existing = fiber.watchSlots[i];
25
25
  if (existing) {
26
- if (existing.key !== key) {
27
- existing.dispose();
28
- fiber.watchSlots[i] = void 0;
29
- } else {
26
+ if (existing.key === key) {
30
27
  existing.fnRef.current = fn;
31
28
  return;
32
29
  }
30
+ existing.dispose();
31
+ fiber.watchSlots[i] = void 0;
33
32
  }
34
33
  const fnRef = { current: fn };
35
- const unsub = mount((value) => fnRef.current(value));
34
+ const unsub = mount((value) => {
35
+ fnRef.current(value);
36
+ });
36
37
  const dispose = () => unsub();
37
38
  fiber.watchSlots[i] = {
38
- key,
39
+ dispose,
39
40
  fnRef,
40
- dispose
41
+ key
41
42
  };
42
- }
43
- function registerWatch(fiber, source, fn) {
43
+ };
44
+ const registerWatch = (fiber, source, fn) => {
44
45
  if (Stream.isStream(source)) {
45
46
  useWatchSlot(fiber, source, (run) => {
46
47
  let active = true;
@@ -56,32 +57,31 @@ function registerWatch(fiber, source, fn) {
56
57
  }
57
58
  const atom = isAtomHandle(source) ? source.atom : source;
58
59
  useWatchSlot(fiber, atom, (run) => fiber.registry.subscribe(atom, run, { immediate: true }), fn);
59
- }
60
+ };
60
61
  /** Run `fn` when `source` changes — and once on mount. Sync, async, and generator components. */
61
- function watch(source, fn) {
62
- registerWatch((isAtomHandle(source) ? handleOwner.get(source) : void 0) ?? getFiber(), source, fn);
62
+ const watch = (source, fn) => {
63
+ const fiber = (isAtomHandle(source) ? handleOwner.get(source) : void 0) ?? getFiber();
64
+ registerWatch(fiber, source, fn);
63
65
  return instr(Effect.void);
64
- }
66
+ };
65
67
 
66
68
  //#endregion
67
69
  //#region src/when.ts
68
- function when(stream, body) {
69
- return instr(Effect.gen(function* () {
70
- const parent = getFiber();
71
- let child;
72
- parent.holes.push({ dispose() {
73
- if (child) closeFiber(child);
74
- child = void 0;
75
- } });
76
- const base = stream;
77
- const src = parent.runtime.ssr ? base.pipe(Stream.take(1)) : base;
78
- yield* Stream.runForEach(src, (value) => Effect.sync(() => {
79
- if (child) closeFiber(child);
80
- child = makeFiber(parent.runtime, parent.root, paint, { onFail: parent.fail });
81
- interpret((() => body(value)), child);
82
- }));
70
+ const when = (stream, body) => instr(Effect.gen(function* whenBody() {
71
+ const parent = getFiber();
72
+ let child;
73
+ parent.holes.push({ dispose() {
74
+ if (child) closeFiber(child);
75
+ child = void 0;
76
+ } });
77
+ const base = stream;
78
+ const src = parent.runtime.ssr ? base.pipe(Stream.take(1)) : base;
79
+ yield* Stream.runForEach(src, (value) => Effect.sync(() => {
80
+ if (child) closeFiber(child);
81
+ child = makeFiber(parent.runtime, parent.root, parent.paintFn, { onFail: parent.fail });
82
+ interpret((() => body(value)), child);
83
83
  }));
84
- }
84
+ }));
85
85
 
86
86
  //#endregion
87
87
  export { Fragment, atom, batch, h, mount, renderToString, watch, when };
@@ -1,4 +1,4 @@
1
- import { r as Fragment } from "./types-Cie0Ihl6.js";
2
- import { n as JSX } from "./vnode-15tImQ6O.js";
1
+ import { i as Fragment } from "./types-DQVTD0ts.js";
2
+ import { n as JSX } from "./vnode-DHBqDHtZ.js";
3
3
  import { jsx, jsxDEV, jsxs } from "./jsx-runtime.js";
4
4
  export { Fragment, type JSX, jsx, jsxDEV, jsxs };
@@ -1,4 +1,4 @@
1
- import { i as Fragment } from "./vnode-DHN2EFHi.js";
1
+ import { i as Fragment } from "./vnode-DP76Gn-b.js";
2
2
  import { jsx, jsxDEV, jsxs } from "./jsx-runtime.js";
3
3
 
4
4
  export { Fragment, jsx, jsxDEV, jsxs };
@@ -1,8 +1,8 @@
1
- import { o as View, r as Fragment } from "./types-Cie0Ihl6.js";
2
- import { n as JSX, t as h } from "./vnode-15tImQ6O.js";
1
+ import { c as View, i as Fragment, o as PropBag, r as ComponentFn } from "./types-DQVTD0ts.js";
2
+ import { n as JSX, t as h } from "./vnode-DHBqDHtZ.js";
3
3
  //#region src/jsx-runtime.d.ts
4
- declare const jsx: (type: string | typeof Fragment | ((p: Record<string, unknown>) => unknown), props: Record<string, unknown> | null, key?: string | number) => ReturnType<typeof h>;
5
- declare const jsxs: (type: string | typeof Fragment | ((p: Record<string, unknown>) => unknown), props: Record<string, unknown> | null, key?: string | number) => ReturnType<typeof h>;
6
- declare const jsxDEV: (type: string | typeof Fragment | ((p: Record<string, unknown>) => unknown), props: Record<string, unknown> | null, key?: string | number) => ReturnType<typeof h>;
4
+ declare const jsx: (type: string | Fragment | ComponentFn, props: PropBag | null, key?: string | number) => ReturnType<typeof h>;
5
+ declare const jsxs: (type: string | Fragment | ComponentFn, props: PropBag | null, key?: string | number) => ReturnType<typeof h>;
6
+ declare const jsxDEV: (type: string | Fragment | ComponentFn, props: PropBag | null, key?: string | number) => ReturnType<typeof h>;
7
7
  //#endregion
8
8
  export { Fragment, type JSX, type View, h, jsx, jsxDEV, jsxs };
@@ -1,4 +1,4 @@
1
- import { i as Fragment, t as h } from "./vnode-DHN2EFHi.js";
1
+ import { i as Fragment, t as h } from "./vnode-DP76Gn-b.js";
2
2
 
3
3
  //#region src/jsx-runtime.ts
4
4
  const jsx = (type, props, key) => h(type, key === void 0 ? props : {