small-state-react 0.1.1 → 0.1.3

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
@@ -40,8 +40,11 @@ npm i small-state-react
40
40
 
41
41
  #### `atomWithRuntimeSnapshot(machine, options?)`
42
42
 
43
- `<M extends AnyMachine>(machine: M | ((get:Getter)=>M), options?: RuntimeOptions<M>) => WritableAtom<Snapshot<M>, [event: SendFnEvent<M>], void>`
43
+ `<M extends AnyMachine>(machine: M | ((get:Getter)=>M), options?: RuntimeOptions<M> & { onPreStart?: (runtime: Runtime<M>) => void }) => WritableAtom<Snapshot<M>, [event: SendFnEvent<M>], void>`
44
+
44
45
 
45
46
  - Returns an atom for the specified machine.
46
47
  - It is initialized as a runtime and started when mounted somewhere. When it is no longer mounted anywhere, the runtime is destroyed.
47
48
  - The values returned when passed to `useAtom` are `[snapshot, send]`.
49
+ - The `onPreStart` option is a hook function that is called immediately before the runtime starts. It receives `runtime` as an argument.
50
+ - This is useful for registering `.onEmitted` or `.subscribe` handlers.
package/dist/index.cjs CHANGED
@@ -21,7 +21,9 @@ function useRuntime(machine, options) {
21
21
  }, [runtime, qOptions]);
22
22
  return {
23
23
  snapshot,
24
- send: runtime.send.bind(runtime),
24
+ send: (event) => {
25
+ runtime.send.apply(runtime, [event]);
26
+ },
25
27
  runtime
26
28
  };
27
29
  }
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { AnyMachine, Runtime, RuntimeOptions, Snapshot } from "small-state";
1
+ import { AnyMachine, Runtime, RuntimeOptions, SendFnEvent, Snapshot } from "small-state";
2
2
  export declare function useRuntime<M extends AnyMachine>(machine: M, options?: RuntimeOptions<M> & {
3
3
  onPreStart?: (runtime: Runtime<M>) => void;
4
4
  }): {
5
5
  snapshot: import("small-state").Snapshot<M>;
6
- send: (event: import("small-state").SendFnEvent<M>) => Runtime<M>;
6
+ send: (event: SendFnEvent<M>) => undefined;
7
7
  runtime: Runtime<M>;
8
8
  };
9
9
  export declare function useSelectedSnapshot<M extends AnyMachine, Sel>(runtime: Runtime<M> | undefined, selector: (snapshot: Snapshot<M>) => Sel, compare?: (current: Sel, next: Sel) => boolean): Sel;
package/dist/index.d.mts CHANGED
@@ -1,9 +1,9 @@
1
- import { AnyMachine, Runtime, RuntimeOptions, Snapshot } from "small-state";
1
+ import { AnyMachine, Runtime, RuntimeOptions, SendFnEvent, Snapshot } from "small-state";
2
2
  export declare function useRuntime<M extends AnyMachine>(machine: M, options?: RuntimeOptions<M> & {
3
3
  onPreStart?: (runtime: Runtime<M>) => void;
4
4
  }): {
5
5
  snapshot: import("small-state").Snapshot<M>;
6
- send: (event: import("small-state").SendFnEvent<M>) => Runtime<M>;
6
+ send: (event: SendFnEvent<M>) => undefined;
7
7
  runtime: Runtime<M>;
8
8
  };
9
9
  export declare function useSelectedSnapshot<M extends AnyMachine, Sel>(runtime: Runtime<M> | undefined, selector: (snapshot: Snapshot<M>) => Sel, compare?: (current: Sel, next: Sel) => boolean): Sel;
package/dist/index.mjs CHANGED
@@ -20,7 +20,9 @@ function useRuntime(machine, options) {
20
20
  }, [runtime, qOptions]);
21
21
  return {
22
22
  snapshot,
23
- send: runtime.send.bind(runtime),
23
+ send: (event) => {
24
+ runtime.send.apply(runtime, [event]);
25
+ },
24
26
  runtime
25
27
  };
26
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "small-state-react",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "React and Jotai bindings for small-state, a lightweight state machine library.",
5
5
  "author": "qyvvy",
6
6
  "license": "MIT",