Skip to content

Instantly share code, notes, and snippets.

@themounthead
Last active December 19, 2019 12:21
Show Gist options
  • Select an option

  • Save themounthead/8ed8d53486d79f8f6142a1dc2de3205f to your computer and use it in GitHub Desktop.

Select an option

Save themounthead/8ed8d53486d79f8f6142a1dc2de3205f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const FRIEND_STATE_TREE = {
initial: 'IDLE',
states: {
IDLE: {
on: {
'ON_LOAD_FRIEND_FEED': 'FRIEND_FEED_WAITING',
},
},
FRIEND_FEED_WAITING: {
entry: 'test',
on: {
'ON_FRIEND_FEED_REPLY': 'FRIEND_FEED_REPLY',
},
after: {5000: { target: 'FRIEND_FEED_TIMEOUT', cond: () => true}},
},
FRIEND_FEED_REPLY: {
on: {
'': [
{ target: 'FRIEND_FEED_EMPTY', cond: () => false},
{ target: 'FRIEND_FEED_ERROR', cond: (context) => false },
{ target: 'FRIEND_FEED_DATA' }
],
},
},
FRIEND_FEED_EMPTY: {
type: 'final',
},
FRIEND_FEED_DATA: {
type: 'final',
},
FRIEND_FEED_ERROR: {
type: 'final',
},
FRIEND_FEED_TIMEOUT: {
type: 'final',
},
},
};
const GROUP_STATE_TREE = {
initial: 'IDLE',
states: {
IDLE: {
on: {
'ON_LOAD_GROUP_FEED': 'GROUP_FEED_WAITING',
},
},
GROUP_FEED_WAITING: {
on: {
'ON_GROUP_FEED_REPLY': 'GROUP_FEED_REPLY',
},
after: {5000: { target: 'GROUP_FEED_TIMEOUT', cond: () => true}},
},
GROUP_FEED_REPLY: {
on: {
'': [
{ target: 'GROUP_FEED_EMPTY', cond: () => false},
{ target: 'GROUP_FEED_ERROR', cond: (context) => false },
{ target: 'GROUP_FEED_DATA' }
],
},
},
GROUP_FEED_EMPTY: {
type: 'final',
},
GROUP_FEED_DATA: {
type: 'final',
},
GROUP_FEED_ERROR: {
type: 'final',
},
GROUP_FEED_TIMEOUT: {
type: 'final',
},
},
};
const fetchMachine = Machine(
{
id: 'FRIEND-GROUP-MACHINE',
type: 'parallel',
context: {
activeTab: true,
},
on: {
'ON_TOGGLE': {
actions: assign((context, event) => ({
activeTab: !context.activeTab
}))
},
},
states: {
FRIEND_VIEW: FRIEND_STATE_TREE,
GROUP_VIEW: GROUP_STATE_TREE,
},
},
{
actions: {
test: (context, event) => {
console.log('handle entry...', context, event);
// console.log('entry...', context, event);
},
sample: (context, event) => {
console.log('alsdasklds!!!');
},
},
guards: {
isFeedEmpty: (context, event) => {
console.log('isFeedEmpty', context, event);
return false;
},
isFeedData: (context, event) => {
console.log('isFeedData', context, event);
return true;
},
},
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment