How to use the xstate.sendParent function in xstate

To help you get started, we’ve selected a few xstate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coodoo / xstate-examples / _old / fsm-service-3-actor / src / fsm / workerActions.js View on Github external
export const workerProgressAssign = assign((ctx, e) => {
	const { progress } = e.job
	// console.log( `workerMachine ${id}: ${progress}` )
	ctx.progress = progress
	return ctx
})

export const workerDoneAssign = assign((ctx, e) => {
	// console.log( '\t[workerDone]', ctx, e )
	const { progress } = e.job
	ctx.progress = progress
	return ctx
})

export const workerDoneSend = sendParent((ctx, e) => ({
	type: MainTypes.updateJob,
	song: ctx,
}))

export const pauseFileAssign = assign((ctx, e) => {
	// console.log('\t[pauseFile]', e.id)
})

export const pauseFileSend = send(
	(ctx, e) => ({
		type: CompServiceTypes.pauseSong,
		data: ctx.id,
	}),
	{ to: 'CompressionService' },
)
github tolads / my-movie-lists / src / state / movies / moviesMachine.js View on Github external
on: {
      [SET_SEARCH_VALUE]: [
        {
          target: 'search.fetching',
          cond: 'shouldFetchMovies',
          actions: 'setSearchValueInState',
        },
        {
          target: 'search.idle',
          actions: 'setSearchValueInState',
        },
      ],
      [FETCH_MOVIE]: {
        target: 'movie.fetching',
        cond: 'shouldFetchMovie',
        actions: sendParent((context, event) => ({
          type: ADD_MOVIE_TO_ACTIVE_LIST,
          movieId: event.id,
        })),
      },
    },
  },
  {
    actions: {
      setSearchValueInState: assign(
        produce((draftContext, action) => {
          draftContext.currentSearchValue = action.value;
        }),
      ),
      movieSearchResultReceived: assign(
        produce((draftContext, event) => {
          draftContext.searchKeys[draftContext.currentSearchValue] = event.data;
github coodoo / xstate-examples / _old / fsm-service-3-actor / src / fsm / workerActions.js View on Github external
(ctx, e) => ({
		type: CompServiceTypes.resumeSong,
		data: { id: ctx.id, progress: ctx.progress },
	}),
	{ to: 'CompressionService' },
)

export const cancelFileSend = send(
	(ctx, e) => ({
		type: CompServiceTypes.cancelSong,
		data: ctx.id,
	}),
	{ to: 'CompressionService' },
)

export const cancelFileSendParent = sendParent((ctx, e) => ({
	type: MainTypes.cancelJob,
	id: ctx.id,
}))