Skip to content

Instantly share code, notes, and snippets.

@barucAlmaguer
Created February 28, 2020 21:11
Show Gist options
  • Save barucAlmaguer/854dcdac84399c9d429ddbbdd849da73 to your computer and use it in GitHub Desktop.
Save barucAlmaguer/854dcdac84399c9d429ddbbdd849da73 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'usersMachine',
type: 'parallel',
context: {
users: [],
selectedUser: null,
userPermissions: null,
apiNames: null,
permissionTypes: null,
relationTypes: null
},
initial: 'viewing_users',
states: {
ui: {
initial: 'users',
states: {
users: {
on: {
VIEW_DETAILS: {
target: 'user_details',
actions: ['setSelectedUser']
}
}
},
user_details: {
on: {
GO_BACK: 'users'
}
}
}
},
fetch_users: {
initial: 'idle',
states: {
idle: {
on: {
'': {
target: 'fetching',
actions: 'fetchUsers'
},
}
},
fetching: {
on: {
RESOLVE_USERS: {
target: 'success',
actions: ['setUsers']
},
REJECT_USERS: 'error'
}
},
success: { type: 'final' },
error: { type: 'final' }
}
},
fetch_schema: {
initial: 'idle',
states: {
idle: {
on: {
'': {
target: 'fetching',
actions: ['fetchSchema']
},
}
},
fetching: {
on: {
RESOLVE_SCH: {
target: 'success',
actions: ['setSchema']
},
REJECT_SCH: 'error'
}
},
success: { type: 'final' },
error: { type: 'final' }
}
},
fetch_permissions: {
initial: 'idle',
states: {
idle: {
on: {
FETCH_PERMS: {
target: 'fetching',
actions: ['fetchUserPermissions']
}
}
},
fetching: {
on: {
RESOLVE_PERMS: {
target: 'success',
actions: ['setUserPermissions']
},
REJECT_PERMS: 'error'
}
},
success: {
on: {
FETCH_PERMS: {
target: 'fetching',
actions: ['fetchUserPermissions']
}
}
},
error: {
on: {
FETCH_PERMS: {
target: 'fetching',
actions: ['fetchUserPermissions']
}
}
}
}
},
update_user_permission: {
initial: 'idle',
states: {
idle: {
on: {
UPDATE_PERM: {
target: 'updating',
actions: ['updateUserPermission']
}
}
},
updating: {
on: {
RESOLVE_UPDATE: {
target: 'success',
actions: ['setUserPermission']
},
REJECT_UPDATE: 'error'
}
},
success: {
on: {
UPDATE_PERM: {
target: 'updating',
actions: ['updateUserPermission']
}
}
},
error: {
on: {
UPDATE_PERM: {
target: 'updating',
actions: ['updateUserPermission']
}
}
}
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment