@atolljs/solidjs 0.1.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 (3) hide show
  1. package/README.md +9 -0
  2. package/package.json +24 -0
  3. package/src/index.ts +38 -0
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @atolljs/solidjs
2
+
3
+ SolidJS bindings for `@atolljs/core` — framework adapter only, no domain code.
4
+
5
+ - `createObservable(source)` — any `ObservableValue` as an `Accessor`.
6
+ - `createSharedValue(memory, key)` — a shared-memory field as an `Accessor`.
7
+ - `createTask(task)` — `{ state }` Accessor of the task snapshot plus `run`/`runOnce`.
8
+
9
+ The consuming app composes these with its own contracts and tasks.
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@atolljs/solidjs",
3
+ "version": "0.1.0",
4
+ "description": "SolidJS bindings — createObservable, createSharedValue, createTask",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.ts"
8
+ },
9
+ "files": [
10
+ "src"
11
+ ],
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "peerDependencies": {
16
+ "@atolljs/core": "0.1.0",
17
+ "solid-js": "^1.9.15"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/jwhenry3/atolljs",
22
+ "directory": "packages/solidjs"
23
+ }
24
+ }
package/src/index.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { createSignal, onCleanup, type Accessor } from 'solid-js';
2
+ import { observe, toTask } from '@atolljs/core';
3
+ import type { AsyncTask, ObservableValue, PathConnector, SharedMemory, SharedSpec, SpecPath, SliceOptions, TaskSnapshot } from '@atolljs/core';
4
+
5
+ /** Wrap any sdk ObservableValue (task snapshot, field observable) in an Accessor. */
6
+ export function createObservable<T>(source: ObservableValue<T>): Accessor<T> {
7
+ const [value, setValue] = createSignal(source.get(), { equals: false });
8
+ onCleanup(source.subscribe((v) => setValue(() => v)));
9
+ return value;
10
+ }
11
+
12
+ /**
13
+ * Bind one shared-memory field to an Accessor. Stays `undefined` until the
14
+ * contract is bound and the field written; updates on every write.
15
+ */
16
+ export function createSharedValue<S extends SharedSpec, K extends SpecPath<S>>(memory: SharedMemory<S>, key: K): Accessor<(PathConnector<S, K> extends { read(): infer T } ? T : never) | undefined>;
17
+ export function createSharedValue<S extends SharedSpec, K extends SpecPath<S>, Sel>(
18
+ memory: SharedMemory<S>,
19
+ key: K,
20
+ select: (value: PathConnector<S, K> extends { read(): infer T } ? T : never) => Sel,
21
+ options?: SliceOptions<Sel>
22
+ ): Accessor<Sel | undefined>;
23
+ export function createSharedValue<S extends SharedSpec, K extends SpecPath<S>, Sel>(
24
+ memory: SharedMemory<S>,
25
+ key: K,
26
+ select?: (value: never) => Sel,
27
+ options?: SliceOptions<Sel>
28
+ ) {
29
+ return createObservable(observe(memory, key, select as never, options as never));
30
+ }
31
+
32
+ /** Bind an AsyncTask or plain async fn (via toTask): `{ state }` is an Accessor of its snapshot; `run`/`runOnce` trigger it. */
33
+ export function createTask<R>(source: AsyncTask<void, R> | (() => Promise<R>)): { state: Accessor<TaskSnapshot<R>>; run: AsyncTask<void, R>['run']; runOnce: AsyncTask<void, R>['runOnce'] };
34
+ export function createTask<A, R>(source: AsyncTask<A, R> | ((input: A) => Promise<R>)): { state: Accessor<TaskSnapshot<R>>; run: AsyncTask<A, R>['run']; runOnce: AsyncTask<A, R>['runOnce'] };
35
+ export function createTask<A, R>(source: AsyncTask<A, R> | ((input: A) => Promise<R>)) {
36
+ const task = toTask(source);
37
+ return { state: createObservable(task), run: task.run, runOnce: task.runOnce };
38
+ }