Skip to content

Instantly share code, notes, and snippets.

@drmikecrowe
Last active July 5, 2020 11:16
Show Gist options
  • Save drmikecrowe/e57234c651ae24c0679f6367ea0771ec to your computer and use it in GitHub Desktop.
Save drmikecrowe/e57234c651ae24c0679f6367ea0771ec to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const states = {
IDLE: 'IDLE',
SEARCHING: 'SEARCHING',
};
const searchNotEmptyTarget = {
target: states.SEARCHING,
cond: (_ctx, evt) => evt.search !== '', // && evt.search.length > 3,
actions: assign({ search: (_ctx, evt) => evt.search }),
};
const searchMachine = Machine({
id: 'search',
initial: states.IDLE,
context: {
search: '',
results: [],
},
states: {
[states.IDLE]: {
on: {
SEARCH_CHANGED: [searchNotEmptyTarget],
},
},
[states.SEARCHING]: {
invoke: {
src: 'fetchResults',
onDone: {
target: states.IDLE,
actions: assign({
results: (_, evt) => evt.data,
}),
},
},
},
},
}, {
services: {
fetchResults: () => new Promise((resolve) => {
setTimeout(resolve([
{
id: '1051557000',
subscribed: true,
title: 'Science Vs',
author: 'Gimlet',
imageSmall:
'https://is3-ssl.mzstatic.com/image/thumb/Podcasts113/v4/b7/56/4f/b7564f9a-84ab-c079-b83e-8390cb32ae06/mza_5953464131050553578.png/60x60bb.jpg',
imageLarge:
'https://is3-ssl.mzstatic.com/image/thumb/Podcasts113/v4/b7/56/4f/b7564f9a-84ab-c079-b83e-8390cb32ae06/mza_5953464131050553578.png/100x100bb.jpg',
feedUrl: 'https://feeds.megaphone.fm/sciencevs',
country: 'USA',
genre: 'Science',
releaseDate: '2020-07-03T03:28:00Z',
episodes: 122,
},
{
id: '998250544',
subscribed: false,
title: 'Science Vs',
author: 'ABC Radio',
imageSmall:
'https://is3-ssl.mzstatic.com/image/thumb/Podcasts62/v4/17/d9/b9/17d9b9b6-82eb-476f-6aea-3620f0ea5ad2/mza_830817199619995877.jpg/60x60bb.jpg',
imageLarge:
'https://is3-ssl.mzstatic.com/image/thumb/Podcasts62/v4/17/d9/b9/17d9b9b6-82eb-476f-6aea-3620f0ea5ad2/mza_830817199619995877.jpg/100x100bb.jpg',
feedUrl: 'http://www.abc.net.au/radio/programs/sciencevs/feed/8604304/podcast.xml',
country: 'USA',
genre: 'Science',
releaseDate: '2015-06-22T02:00:00Z',
episodes: 9,
},
{
id: '1470525128',
subscribed: false,
title: 'Science vs Fiction',
author: 'Science vs Fiction',
imageSmall:
'https://is2-ssl.mzstatic.com/image/thumb/Podcasts123/v4/9f/33/ca/9f33ca7d-83c2-3423-8147-777ebc6cc23d/mza_3897731350303198230.jpg/60x60bb.jpg',
imageLarge:
'https://is2-ssl.mzstatic.com/image/thumb/Podcasts123/v4/9f/33/ca/9f33ca7d-83c2-3423-8147-777ebc6cc23d/mza_3897731350303198230.jpg/100x100bb.jpg',
feedUrl: 'https://audioboom.com/channels/5020282.rss',
country: 'USA',
genre: 'TV & Film',
releaseDate: '2020-06-08T01:21:00Z',
episodes: 29,
},
{
id: '213635669',
subscribed: false,
title: 'Science Vs Nature PodCast',
author: 'Science Vs Nature',
imageSmall:
'https://is5-ssl.mzstatic.com/image/thumb/Podcasts113/v4/d1/5d/98/d15d98aa-0ba2-11f3-f049-ff8ff2e42b49/mza_13880519086873937688.jpg/60x60bb.jpg',
imageLarge:
'https://is5-ssl.mzstatic.com/image/thumb/Podcasts113/v4/d1/5d/98/d15d98aa-0ba2-11f3-f049-ff8ff2e42b49/mza_13880519086873937688.jpg/100x100bb.jpg',
feedUrl: 'http://svn.podOmatic.com/rss2.xml',
country: 'USA',
genre: 'Music',
releaseDate: '2014-07-17T13:00:00Z',
episodes: 5,
},
{
id: '1114594773',
subscribed: false,
title: 'Nutrition Bytes: What We Think We Know vs What Science Says | Bytes to Inform Your Everyday Life',
author: 'Cassandra Collins: Nutritionist, Health Enthusiast, Research Addict',
imageSmall:
'https://is3-ssl.mzstatic.com/image/thumb/Podcasts113/v4/78/d8/2d/78d82d8b-494c-a8c0-fd61-07558fbd9d2b/mza_6336824238216585504.jpg/60x60bb.jpg',
imageLarge:
'https://is3-ssl.mzstatic.com/image/thumb/Podcasts113/v4/78/d8/2d/78d82d8b-494c-a8c0-fd61-07558fbd9d2b/mza_6336824238216585504.jpg/100x100bb.jpg',
feedUrl: 'http://feeds.soundcloud.com/users/soundcloud:users:227378928/sounds.rss',
country: 'USA',
genre: 'Science',
releaseDate: '2016-05-16T18:49:00Z',
episodes: 1,
},
{
id: '1282545453',
subscribed: false,
title: 'Alan & Jeremy Vs Science Fiction',
author: 'Alan & jeremy Vs Science Fiction',
imageSmall:
'https://is4-ssl.mzstatic.com/image/thumb/Podcasts123/v4/7a/30/9a/7a309a43-ff48-a9e6-590c-c4c19dc0327d/mza_4889498292286343779.jpg/60x60bb.jpg',
imageLarge:
'https://is4-ssl.mzstatic.com/image/thumb/Podcasts123/v4/7a/30/9a/7a309a43-ff48-a9e6-590c-c4c19dc0327d/mza_4889498292286343779.jpg/100x100bb.jpg',
feedUrl: 'https://alanandjeremyvssf.libsyn.com/rss',
country: 'USA',
genre: 'Books',
releaseDate: '2020-03-11T01:01:00Z',
episodes: 41,
},
{
id: '1514157140',
subscribed: false,
title: 'Science vs. God',
author: 'Ansley Burnett',
imageSmall:
'https://is5-ssl.mzstatic.com/image/thumb/Podcasts113/v4/03/ba/d5/03bad522-8d45-c9a5-ed63-8e7dc925b593/mza_1945842574264062232.jpg/60x60bb.jpg',
imageLarge:
'https://is5-ssl.mzstatic.com/image/thumb/Podcasts113/v4/03/ba/d5/03bad522-8d45-c9a5-ed63-8e7dc925b593/mza_1945842574264062232.jpg/100x100bb.jpg',
feedUrl: 'https://anchor.fm/s/202b0b7c/podcast/rss',
country: 'USA',
genre: 'Religion & Spirituality',
releaseDate: '2020-06-10T20:38:00Z',
episodes: 9,
},
], 1000))
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment