@thomasfosterau/effect-svelte 0.0.0

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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +58 -0
  3. package/dist/Store.d.ts +154 -0
  4. package/dist/Store.js +183 -0
  5. package/dist/Store.js.map +1 -0
  6. package/dist/_virtual/_rolldown/runtime.js +13 -0
  7. package/dist/context.svelte.d.ts +37 -0
  8. package/dist/context.svelte.js +53 -0
  9. package/dist/context.svelte.js.map +1 -0
  10. package/dist/derived.svelte.d.ts +43 -0
  11. package/dist/derived.svelte.js +65 -0
  12. package/dist/derived.svelte.js.map +1 -0
  13. package/dist/effect.svelte.d.ts +51 -0
  14. package/dist/effect.svelte.js +68 -0
  15. package/dist/effect.svelte.js.map +1 -0
  16. package/dist/emitter.d.ts +45 -0
  17. package/dist/emitter.js +60 -0
  18. package/dist/emitter.js.map +1 -0
  19. package/dist/index.d.ts +14 -0
  20. package/dist/index.js +13 -0
  21. package/dist/internal/result.svelte.js +36 -0
  22. package/dist/internal/result.svelte.js.map +1 -0
  23. package/dist/internal/run.d.ts +15 -0
  24. package/dist/internal/run.js +25 -0
  25. package/dist/internal/run.js.map +1 -0
  26. package/dist/internal/subscribe.js +79 -0
  27. package/dist/internal/subscribe.js.map +1 -0
  28. package/dist/query.svelte.d.ts +45 -0
  29. package/dist/query.svelte.js +41 -0
  30. package/dist/query.svelte.js.map +1 -0
  31. package/dist/reactivity.svelte.d.ts +123 -0
  32. package/dist/reactivity.svelte.js +186 -0
  33. package/dist/reactivity.svelte.js.map +1 -0
  34. package/dist/runtime.d.ts +81 -0
  35. package/dist/runtime.js +85 -0
  36. package/dist/runtime.js.map +1 -0
  37. package/dist/scope.svelte.d.ts +49 -0
  38. package/dist/scope.svelte.js +68 -0
  39. package/dist/scope.svelte.js.map +1 -0
  40. package/dist/stream.svelte.d.ts +48 -0
  41. package/dist/stream.svelte.js +34 -0
  42. package/dist/stream.svelte.js.map +1 -0
  43. package/dist/subscription.svelte.d.ts +69 -0
  44. package/dist/subscription.svelte.js +69 -0
  45. package/dist/subscription.svelte.js.map +1 -0
  46. package/package.json +53 -0
@@ -0,0 +1,34 @@
1
+ import { getRuntimeContext } from "./context.svelte.js";
2
+ import { streamState } from "./internal/subscribe.js";
3
+ //#region src/stream.svelte.ts
4
+ /**
5
+ * Subscribe to a Stream and collect emissions.
6
+ *
7
+ * The subscription starts the first time `current`/`values`/`latest` is read
8
+ * inside an effect or template, and is interrupted automatically when the last
9
+ * reader is destroyed (via Svelte's `createSubscriber`).
10
+ *
11
+ * @example
12
+ * ```svelte
13
+ * <script lang="ts">
14
+ * import { useStream } from '@thomasfosterau/effect-svelte';
15
+ * import { Stream, Schedule } from 'effect';
16
+ *
17
+ * const counter = useStream(
18
+ * Stream.iterate(0, n => n + 1).pipe(
19
+ * Stream.schedule(Schedule.spaced('1 second'))
20
+ * )
21
+ * );
22
+ * <\/script>
23
+ *
24
+ * <p>Latest: {counter.latest}</p>
25
+ * <p>All values: {counter.values.join(', ')}</p>
26
+ * ```
27
+ */
28
+ function useStream(stream) {
29
+ return streamState(getRuntimeContext(), () => stream);
30
+ }
31
+ //#endregion
32
+ export { useStream };
33
+
34
+ //# sourceMappingURL=stream.svelte.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.svelte.js","names":["getRuntime"],"sources":["../src/stream.svelte.ts"],"sourcesContent":["import type { Stream } from \"effect\";\nimport type * as AsyncResult from \"effect/unstable/reactivity/AsyncResult\";\nimport { getRuntime } from \"./context.svelte.js\";\nimport type { RuntimeLike } from \"./internal/run.js\";\nimport { streamState } from \"./internal/subscribe.js\";\n\nexport interface UseStreamReturn<A, E> {\n /**\n * The current result state of the stream. `Initial`/`Success` carry a\n * `waiting` flag while the stream is still live (stale-while-revalidate), and\n * settle to a non-waiting `Success`/`Failure` once it completes.\n */\n readonly current: AsyncResult.AsyncResult<ReadonlyArray<A>, E>;\n\n /**\n * All values emitted by the stream so far\n */\n readonly values: ReadonlyArray<A>;\n\n /**\n * The most recent value emitted by the stream (undefined if none)\n */\n readonly latest: A | undefined;\n}\n\n/**\n * Subscribe to a Stream and collect emissions.\n *\n * The subscription starts the first time `current`/`values`/`latest` is read\n * inside an effect or template, and is interrupted automatically when the last\n * reader is destroyed (via Svelte's `createSubscriber`).\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { useStream } from '@thomasfosterau/effect-svelte';\n * import { Stream, Schedule } from 'effect';\n *\n * const counter = useStream(\n * Stream.iterate(0, n => n + 1).pipe(\n * Stream.schedule(Schedule.spaced('1 second'))\n * )\n * );\n * </script>\n *\n * <p>Latest: {counter.latest}</p>\n * <p>All values: {counter.values.join(', ')}</p>\n * ```\n */\nexport function useStream<A, E, R>(stream: Stream.Stream<A, E, R>): UseStreamReturn<A, E> {\n const runtime = getRuntime() as RuntimeLike<R>;\n return streamState(runtime, () => stream);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,SAAgB,UAAmB,QAAuD;CAExF,OAAO,YADSA,kBACS,SAAS,MAAM;AAC1C"}
@@ -0,0 +1,69 @@
1
+ import { PubSub, SubscriptionRef } from "effect";
2
+
3
+ //#region src/subscription.svelte.d.ts
4
+ interface UseSubscriptionRefReturn<A> {
5
+ /**
6
+ * The current value of the SubscriptionRef
7
+ */
8
+ readonly current: A;
9
+ }
10
+ /**
11
+ * Subscribe to an Effect SubscriptionRef and get reactive updates.
12
+ * Returns an object exposing the current value via the `current` property.
13
+ *
14
+ * The initial value is read synchronously; the subscription that keeps it up to
15
+ * date starts when `current` is first read inside an effect or template, and is
16
+ * interrupted when the last reader is destroyed.
17
+ *
18
+ * @example
19
+ * ```svelte
20
+ * <script lang="ts">
21
+ * import { useSubscriptionRef } from '@thomasfosterau/effect-svelte';
22
+ * import { SubscriptionRef, Effect } from 'effect';
23
+ *
24
+ * // Assume counterRef is a SubscriptionRef<number>
25
+ * const count = useSubscriptionRef(counterRef);
26
+ * </script>
27
+ *
28
+ * <p>Count: {count.current}</p>
29
+ * ```
30
+ */
31
+ declare function useSubscriptionRef<A>(ref: SubscriptionRef.SubscriptionRef<A>): UseSubscriptionRefReturn<A>;
32
+ interface UsePubSubReturn<A> {
33
+ /**
34
+ * All values received from the PubSub
35
+ */
36
+ readonly values: ReadonlyArray<A>;
37
+ /**
38
+ * The most recent value (undefined if none)
39
+ */
40
+ readonly latest: A | undefined;
41
+ }
42
+ /**
43
+ * Subscribe to an Effect PubSub and collect messages.
44
+ *
45
+ * The subscription starts when `values`/`latest` is first read inside an effect
46
+ * or template, and is interrupted when the last reader is destroyed.
47
+ *
48
+ * @example
49
+ * ```svelte
50
+ * <script lang="ts">
51
+ * import { usePubSub } from '@thomasfosterau/effect-svelte';
52
+ * import { PubSub } from 'effect';
53
+ *
54
+ * // Assume messagePubSub is a PubSub<string>
55
+ * const messages = usePubSub(messagePubSub);
56
+ * </script>
57
+ *
58
+ * <p>Latest: {messages.latest}</p>
59
+ * <ul>
60
+ * {#each messages.values as msg}
61
+ * <li>{msg}</li>
62
+ * {/each}
63
+ * </ul>
64
+ * ```
65
+ */
66
+ declare function usePubSub<A>(pubsub: PubSub.PubSub<A>): UsePubSubReturn<A>;
67
+ //#endregion
68
+ export { UsePubSubReturn, UseSubscriptionRefReturn, usePubSub, useSubscriptionRef };
69
+ //# sourceMappingURL=subscription.svelte.d.ts.map
@@ -0,0 +1,69 @@
1
+ import { getRuntimeContext } from "./context.svelte.js";
2
+ import { runSync } from "./internal/run.js";
3
+ import { streamState, valueState } from "./internal/subscribe.js";
4
+ import { Stream, SubscriptionRef } from "effect";
5
+ //#region src/subscription.svelte.ts
6
+ /**
7
+ * Subscribe to an Effect SubscriptionRef and get reactive updates.
8
+ * Returns an object exposing the current value via the `current` property.
9
+ *
10
+ * The initial value is read synchronously; the subscription that keeps it up to
11
+ * date starts when `current` is first read inside an effect or template, and is
12
+ * interrupted when the last reader is destroyed.
13
+ *
14
+ * @example
15
+ * ```svelte
16
+ * <script lang="ts">
17
+ * import { useSubscriptionRef } from '@thomasfosterau/effect-svelte';
18
+ * import { SubscriptionRef, Effect } from 'effect';
19
+ *
20
+ * // Assume counterRef is a SubscriptionRef<number>
21
+ * const count = useSubscriptionRef(counterRef);
22
+ * <\/script>
23
+ *
24
+ * <p>Count: {count.current}</p>
25
+ * ```
26
+ */
27
+ function useSubscriptionRef(ref) {
28
+ const runtime = getRuntimeContext();
29
+ return valueState(runtime, runSync(runtime)(SubscriptionRef.get(ref)), () => SubscriptionRef.changes(ref));
30
+ }
31
+ /**
32
+ * Subscribe to an Effect PubSub and collect messages.
33
+ *
34
+ * The subscription starts when `values`/`latest` is first read inside an effect
35
+ * or template, and is interrupted when the last reader is destroyed.
36
+ *
37
+ * @example
38
+ * ```svelte
39
+ * <script lang="ts">
40
+ * import { usePubSub } from '@thomasfosterau/effect-svelte';
41
+ * import { PubSub } from 'effect';
42
+ *
43
+ * // Assume messagePubSub is a PubSub<string>
44
+ * const messages = usePubSub(messagePubSub);
45
+ * <\/script>
46
+ *
47
+ * <p>Latest: {messages.latest}</p>
48
+ * <ul>
49
+ * {#each messages.values as msg}
50
+ * <li>{msg}</li>
51
+ * {/each}
52
+ * </ul>
53
+ * ```
54
+ */
55
+ function usePubSub(pubsub) {
56
+ const state = streamState(getRuntimeContext(), () => Stream.fromPubSub(pubsub));
57
+ return {
58
+ get values() {
59
+ return state.values;
60
+ },
61
+ get latest() {
62
+ return state.latest;
63
+ }
64
+ };
65
+ }
66
+ //#endregion
67
+ export { usePubSub, useSubscriptionRef };
68
+
69
+ //# sourceMappingURL=subscription.svelte.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription.svelte.js","names":["getRuntime"],"sources":["../src/subscription.svelte.ts"],"sourcesContent":["import { PubSub, Stream, SubscriptionRef } from \"effect\";\nimport { getRuntime } from \"./context.svelte.js\";\nimport { runSync, type RuntimeLike } from \"./internal/run.js\";\nimport { streamState, valueState } from \"./internal/subscribe.js\";\n\nexport interface UseSubscriptionRefReturn<A> {\n /**\n * The current value of the SubscriptionRef\n */\n readonly current: A;\n}\n\n/**\n * Subscribe to an Effect SubscriptionRef and get reactive updates.\n * Returns an object exposing the current value via the `current` property.\n *\n * The initial value is read synchronously; the subscription that keeps it up to\n * date starts when `current` is first read inside an effect or template, and is\n * interrupted when the last reader is destroyed.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { useSubscriptionRef } from '@thomasfosterau/effect-svelte';\n * import { SubscriptionRef, Effect } from 'effect';\n *\n * // Assume counterRef is a SubscriptionRef<number>\n * const count = useSubscriptionRef(counterRef);\n * </script>\n *\n * <p>Count: {count.current}</p>\n * ```\n */\nexport function useSubscriptionRef<A>(\n ref: SubscriptionRef.SubscriptionRef<A>,\n): UseSubscriptionRefReturn<A> {\n const runtime = getRuntime() as RuntimeLike<never>;\n\n // Get the initial value synchronously so it is available before (and during\n // SSR, instead of) the subscription. `SubscriptionRef.changes` re-emits the\n // current value on subscribe, so no update is missed.\n const initial = runSync(runtime)(SubscriptionRef.get(ref));\n return valueState(runtime, initial, () => SubscriptionRef.changes(ref));\n}\n\nexport interface UsePubSubReturn<A> {\n /**\n * All values received from the PubSub\n */\n readonly values: ReadonlyArray<A>;\n\n /**\n * The most recent value (undefined if none)\n */\n readonly latest: A | undefined;\n}\n\n/**\n * Subscribe to an Effect PubSub and collect messages.\n *\n * The subscription starts when `values`/`latest` is first read inside an effect\n * or template, and is interrupted when the last reader is destroyed.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { usePubSub } from '@thomasfosterau/effect-svelte';\n * import { PubSub } from 'effect';\n *\n * // Assume messagePubSub is a PubSub<string>\n * const messages = usePubSub(messagePubSub);\n * </script>\n *\n * <p>Latest: {messages.latest}</p>\n * <ul>\n * {#each messages.values as msg}\n * <li>{msg}</li>\n * {/each}\n * </ul>\n * ```\n */\nexport function usePubSub<A>(pubsub: PubSub.PubSub<A>): UsePubSubReturn<A> {\n const runtime = getRuntime() as RuntimeLike<never>;\n const state = streamState(runtime, () => Stream.fromPubSub(pubsub));\n return {\n get values() {\n return state.values;\n },\n get latest() {\n return state.latest;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,mBACd,KAC6B;CAC7B,MAAM,UAAUA,kBAAW;CAM3B,OAAO,WAAW,SADF,QAAQ,OAAO,EAAE,gBAAgB,IAAI,GAAG,CACvB,SAAS,gBAAgB,QAAQ,GAAG,CAAC;AACxE;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,UAAa,QAA8C;CAEzE,MAAM,QAAQ,YADEA,kBACgB,SAAS,OAAO,WAAW,MAAM,CAAC;CAClE,OAAO;EACL,IAAI,SAAS;GACX,OAAO,MAAM;EACf;EACA,IAAI,SAAS;GACX,OAAO,MAAM;EACf;CACF;AACF"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@thomasfosterau/effect-svelte",
3
+ "version": "0.0.0",
4
+ "description": "Effect integration for Svelte 5 runes",
5
+ "keywords": [
6
+ "effect",
7
+ "functional-programming",
8
+ "runes",
9
+ "svelte",
10
+ "typescript"
11
+ ],
12
+ "homepage": "https://github.com/thomasfosterau/effect-svelte/tree/main/packages/svelte#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/thomasfosterau/effect-svelte/issues"
15
+ },
16
+ "license": "MIT",
17
+ "author": "Thomas Foster",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/thomasfosterau/effect-svelte.git",
21
+ "directory": "packages/svelte"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "type": "module",
29
+ "main": "./dist/index.js",
30
+ "module": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js"
36
+ }
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "peerDependencies": {
42
+ "effect": "^4.0.0-beta.75",
43
+ "svelte": "^5.40.0"
44
+ },
45
+ "engines": {
46
+ "node": "^20.19.0 || >=22.12.0"
47
+ },
48
+ "scripts": {
49
+ "build": "vp pack",
50
+ "test": "vp test",
51
+ "clean": "rm -rf dist"
52
+ }
53
+ }