Skip to content

Usage with RxJS #1452

Sep 11, 2020 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

and assigning the resulting data

You'll have to forward the information using an event:

import { assign, createMachine } from 'xstate'
import {from } from 'rxjs'
import { map } from 'rxjs/operators'

const numbers$ = from([1, 2, 3, 4])

type MContext = { total: number }
type MEvent = { type: 'UPDATE', number: number }

const machine = createMachine<MContext, MEvent>({
  initial: 'noop',
  context: {
    total: 0,
  },
  invoke: {
    src: () => numbers$.pipe(map(number => ({ type: 'UPDATE', number}))),
  },
  on: {
    UPDATE: {
      actions: assign({ total: (ctx, evt) => ctx.total + evt.number })
    }
  },
  states: {
    noop: {
      
    }
  }
})

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@brandonpittman
Comment options

Answer selected by brandonpittman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants