Skip to content

@xstate/store@4.3.0-alpha.2

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 02 Jul 00:16
91d5bed

Patch Changes

  • 0f0d6e2: Fixed fromStore actor logic so that emitted events and enqueued effects run again. Previously, enq.emit(...) and enq.effect(...) inside a transition were silently dropped.

    const storeLogic = fromStore({
      context: (count: number) => ({ count }),
      schemas: {
        emitted: {
          increased: z.object({ upBy: z.number() })
        }
      },
      on: {
        inc: (ctx, ev: { by: number }, enq) => {
          enq.emit.increased({ upBy: ev.by }); // now emitted
          return { ...ctx, count: ctx.count + ev.by };
        }
      }
    });
    
    const actor = createActor(storeLogic, { input: 42 });
    actor.on('increased', (e) => console.log(e.upBy));
    actor.start();
    actor.send({ type: 'inc', by: 8 }); // logs: 8