function transition(state, event) {
switch (state) {
case 'idle':
switch (event) {
case 'FETCH':
return 'pending';
default:
return state;
}
case 'pending':
switch (event) {
case 'RESOLVE':
return 'resolved';
case 'REJECT':
return 'rejected';
default:
return state;
}
default:
return state;
}
}
import { Machine } from 'xstate';
const fetchMachine = Machine({
id: 'fetch',
initial: 'idle',
states: {
idle: {
on: {
FETCH: 'pending'
}
},
pending: {
on: {
RESOLVE: 'resolved',
REJECT: 'rejected'
}
},
resolved: {
type: 'final'
},
rejected: {}
}
});