Major Changes
-
1e2776f:
@xstate/solidnow requires Solid 2 (solid-js^2.0.3). Stay on@xstate/solid2.x for Solid 1.useActor,useActorRef,useMachineandfromActorRefkeep their signatures. The snapshot is still a deeply reactive store: a read such assnapshot.context.todos[0].doneonly re-runs when that value changes.- Actor refs and the machine in a snapshot are served as the real objects, not store proxies, so
snapshot.children.child.subscribe(...)andfromActorRef(snapshot.context.ref)work as before. Other class instances incontextare wrapped like any Solid store value; pass a class tomarkRawfromsolid-jsto keep its instances as they are. - The actor starts in
onSettledinstead ofonMount. useActor,useActorRefanduseMachinealso accept a function that returns an actor, so the actor can be derived from props or async data without reading them in the component body. The hook owns each actor the function returns: when it returns a new one, the old actor is stopped and the new one started, and the snapshot follows it. In this formuseActorRefand the third tuple item are accessors.
const [snapshot, send] = useActor(() => createActor(checkoutMachine, { input: { cartId: props.cartId } }) );
- As with every Solid 2 write, a transition reaches the snapshot when Solid flushes, on the next microtask. To read the new snapshot right after
send(...)outside a reactive scope, such as in a test, callflush()fromsolid-jsfirst. InsideonSettledor an effect callbackflush()is a no-op, because a flush is already running; defer the read withqueueMicrotask(...)there.
import { flush } from 'solid-js'; send({ type: 'toggle' }); flush(); expect(snapshot.value).toBe('active');