Const
An object that represents the partial context to update, or a function that returns an object that represents the partial context to update.
import { createMachine, assign } from 'xstate';
const countMachine = createMachine({
context: {
count: 0,
message: ''
},
on: {
inc: {
actions: assign({
count: ({ context }) => context.count + 1
})
},
updateMessage: {
actions: assign(({ context, event }) => {
return {
message: event.message.trim()
};
})
}
}
});
Emits an event to event handlers registered on the actor via actor.on(event, handler)
.
import { emit } from 'xstate';
const machine = createMachine({
// ...
on: {
something: {
actions: emit({
type: 'emitted',
some: 'data'
})
}
}
// ...
});
const actor = createActor(machine).start();
actor.on('emitted', (event) => {
console.log(event);
});
actor.send({ type: 'something' });
// logs:
// {
// type: 'emitted',
// some: 'data'
// }
Updates the current context of the machine.