Skip to content

Instantly share code, notes, and snippets.

@jonathanstiansen
Last active April 4, 2021 17:23
Show Gist options
  • Save jonathanstiansen/3d631dbf6f7df099096dc7a77a77189f to your computer and use it in GitHub Desktop.
Save jonathanstiansen/3d631dbf6f7df099096dc7a77a77189f 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 newborn = ({
id: 'newborn',
initial: 'idle',
states: {
idle: {
on: {
}
}
}
});
const sleepingWakeUpsFor12To18WeekOlds = {id: 'infantWakeUpsFor12To18Weeks', initial: 'howLongSleeping12to18WeekOld',
states: {
howLongSleeping12to18WeekOld: {on:{
isLessThan5Hours: 'howDoesBabyFallAsleep',isMoreThan5Hours: 'howOftenIsBabyUp'
}},
howOftenIsBabyUp: {on: {
every2AndAHalfHours: 'trySleepAssocation', is3HourStretch: 'threeHoursIsGood'
}},
threeHoursIsGood: {type: 'final'},
trySleepAssocation: {on: {
isFedToSleep: 'tryBabyFallingSleepOnOwn',
isBouncedToSleep: 'tryFallingSleepWithoutBounce',
isPutDownOnTheirOwn: 'whenDoesUsePacifier'
}},
tryFallingSleepWithoutBounce: {type: 'final'},
tryBabyFallingSleepOnOwn: {type: 'final'},
howDoesBabyFallAsleep: {on: {
isFedToSleep: 'tryNotFeedingToSleep',
isRockedOrBouncedToSleep: 'tryNotBouncingToSleep',
isSetDownIndepedantly: 'whenDoesUsePacifier'
}},
whenDoesUsePacifier: {on: {isUsingOnFallingSleep: 'tryNoPacifier'}},
tryNoPacifier: {on: {next: 'whenFeedingAlsoHappeningBeforeSleep'}},
whenFeedingAlsoHappeningBeforeSleep: {on:{isHappeningRightBeforeBed: 'tryEarlierFeed', isNotHappeningRightBeforeBed: 'noteOnEarlierFeed'}},
noteOnEarlierFeed: {on: {next: 'tryLeavingBabyInBed'}},
tryEarlierFeed: {on: {next: 'tryLeavingBabyInBed'}},
tryLeavingBabyInBed: {type: 'final'},
tryNotBouncingToSleep: {type: 'final'},
tryNotFeedingToSleep: {type: "final"},
}
}
const infant = {
id: 'infant',
initial: 'whenAreYouHavingSleepTrouble',
states: {
whenAreYouHavingSleepTrouble: {on:{
isNotFallingAsleep: 'howOld',
isNotStayingAsleep: 'whichNaps'
}},
whichNaps: {on:{
shortNaps: 'babyIsNormal',
bothNapsAndSleep: 'tryWorkOnNighttime',
}},
tryWorkOnNighttime: {on: {
next: 'howTightlySwaddledForBed'
} },
howTightlySwaddledForBed: {on:{isNotTightlySwaddled: 'trySwaddlingForSleep'}},
trySwaddlingForSleep: {on: {next: 'howMuchLightForSleep'}},
howMuchLightForSleep: {on: {
isPitchBlack: 'howMuchWhiteNoiseForSleep',
isNotPitchBlack: 'tryDarkeningRoomForSleep'
}},
howMuchWhiteNoiseForSleep: {on: {
isContinuousWhiteNoise: 'howMuchNappingBeforeSleep'
}},
howMuchNappingBeforeSleep: {on: {
isLessThan2Hours: 'tryEarlierSleepTime'
}},
tryEarlierSleepTime: {on: {
next: 'howOld6To18'
}},
howOld6To18: {on: {
is6To12Weeks: 'howLongBeforeFirstWakeUpForSleep',
is12To18WeeksOld: 'sleepingWakeUpsFor12To18WeekOlds'
}},
// These are 12-18 week sleeping wake ups
sleepingWakeUpsFor12To18WeekOlds: {
...sleepingWakeUpsFor12To18WeekOlds,
},
// These are 6-12 week sleeping wake ups
howLongBeforeFirstWakeUpForSleep: {on:{
lessThan4Hours: 'howDoesBabyActuallyFallAsleep',
moreThan4Hours:
'howOftenWakeUpsAfterFirstWake'
}},
howOftenWakeUpsAfterFirstWake: {on: {
isEvery2Hours: 'isMostlyNormalWakeUps',
isEvery2andAHalfHours: 'isNormalWakeUps',
}},
isNormalWakeUps:{type: 'final'},
isMostlyNormalWakeUps: {on: {next: 'howDoesBabyActuallyFallAsleep'}},
howDoesBabyActuallyFallAsleep:{ on:{
isFedToSleep: 'tryLettingBabyFallAsleepWithoutFeeding',
isRockedOrBouncedToSleep: 'tryNotLullingBabyToSleep',
isCuddledOrHeldToSleep: 'tryLettingBabyFallAsleepInCrib',
isFallingSleepOnTheirOwn: 'tryGivingThemTimeToFallBackAsleep'
}},
tryLettingBabyFallAsleepInCrib: {type: 'final'},
tryGivingThemTimeToFallBackAsleep: {type: 'final'},
tryNotLullingBabyToSleep: {type: 'final'},
tryLettingBabyFallAsleepWithoutFeeding: {type: 'final'},
tryDarkeningRoomForSleep: {on:{
next: 'howMuchWhiteNoiseForSleep'
}},
babyIsNormal: {type: 'final'},
howOld: {
on: { is6To12Weeks: 'howTightIsSwaddle', is12To18Weeks: 'howMuchDoes12To18Sleep' }
},
// 12to18 week
howMuchDoes12To18Sleep: {on: {
lessThan2Hours: 'tryMoreWake12to18',
about2Hours: 'tryProgressiveWakeWindows12to18',
moreThan2Hours: 'tryShorterWakeWindows12to18',
}},
tryShorterWakeWindows12to18: {on: {
isFeedingBeforeBed: 'tryEarlierFeeding',
isFeedingAround45MinutesBeforeBed: 'tryWakeWindows',
isFeedingMoreThan60MinutesBeforeBed: 'tryClarificationOnFeeding'
}},
tryProgressiveWakeWindows12to18: {on: {
isFeedingBeforeBed: 'tryEarlierFeeding',
isFeedingAround45MinutesBeforeBed: 'tryWakeWindows',
isFeedingMoreThan60MinutesBeforeBed: 'tryClarificationOnFeeding'
}},
tryMoreWake12to18: {on: {
isFeedingBeforeBed: 'tryEarlierFeeding',
isFeedingAround45MinutesBeforeBed: 'tryWakeWindows',
isFeedingMoreThan60MinutesBeforeBed: 'tryClarificationOnFeeding'
}},
tryClarificationOnFeeding: {type: 'final'},
tryWakeWindows: {type: 'final'},
tryEarlierFeeding: {type: 'final'},
// 6-12 week
howTightIsSwaddle: {
on: {isTightlySwaddled: 'howDarkIsRoom', isNotTightlySwaddled: 'trySwaddling'}
},
trySwaddling: {on:{next: 'howDarkIsRoom'}},
howDarkIsRoom: {
on: {isPitchBlack: 'hasWhiteNoise', hasLightInIt: 'tryDarkeningRoom'}
},
tryDarkeningRoom: { on: {next: 'hasWhiteNoise'}},
hasWhiteNoise: {
on: {isContinous: 'howLongWakeWindows', isNotContinuous: 'tryWhiteNoise'}
},
tryWhiteNoise: {
on: {next: 'howLongWakeWindows'}
},
howLongWakeWindows: {
on: {
isLessThanAnHour: 'babyIsUnderTired',
aboutAnHour: 'tryLongerLateWakeWindows',
isAbout75Minutes: 'tryVariableWakeWindows',
isAbout90Minutes: 'tryVariableWakeWindows',
isAbout2Hours: 'tryShorterWakeWindows',
isMoreThan2Hours: 'tryShorterWakeWindows',
}
},
tryShorterWakeWindows: {
on:{
doingEatAwakeSleep: 'asGoodAsItGets',
notEatAwakeSleep: 'tryEatAwaySleep'
}
},
tryVariableWakeWindows: {
on: {
doingEatAwakeSleep: 'asGoodAsItGets',
notEatAwakeSleep: 'tryEatAwaySleep'
}
},
tryLongerLateWakeWindows: {
on: {doingEatAwakeSleep: 'asGoodAsItGets', notEatAwakeSleep: 'tryEatAwaySleep'}
},
babyIsUnderTired: {
on: {
doingEatAwakeSleep: 'asGoodAsItGets', notEatAwakeSleep: 'tryEatAwaySleep'
},
},
tryEatAwaySleep: {type: 'final'},
asGoodAsItGets: {type: 'final'},
}
}
const toddler = ({
id: 'toddler',
initial: 'idle',
states: {
idle: {
on: {
}
}
}
});
const totalFlow = Machine({
id: 'totalFlow',
initial: 'determineAge',
states: {
determineAge: {
on: {
answerToddler: 'toddler',
answerInfant: 'infant',
answerNewborn: 'newborn',
},
},
toddler: { ...toddler },
infant: {...infant} ,
newborn: { ...newborn },
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment