This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Col({ | |
as = "div", | |
justifyContent, | |
alignItems, | |
flex, | |
children | |
}) { | |
return createElement(as, { | |
className: css({ | |
display: "flex", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Spacer({ size }) { | |
return ( | |
<span | |
className={css({ | |
display: "block", | |
width: `var(--spacing-${size})`, | |
height: `var(--spacing-${size})` | |
})} | |
aria-hidden | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Good | |
let { parameters, customParameters } = connection; | |
let firstName = customParameters.get("FirstName"); | |
let lastName = customParameters.get("LastName"); | |
// Lets say we now need to pass eventId. | |
// One could easily add it inside caller as it | |
// already has multiple props, and things are a bit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code handles complexity higher in the tree. | |
// | |
// It makes higher-level components more complicated, but the whole | |
// rendering logic is contained in a single place, which might | |
// help long-term maintenance. | |
function Call() { | |
let { state, send } = useContext(TelecomContext); | |
let { caller } = state.context; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copy and paste into https://statecharts.github.io/xstate-viz/ | |
const paginationMachine = Machine( | |
{ | |
id: "pagination", | |
initial: "idle", | |
states: { | |
idle: {}, | |
debouncing: { | |
onEntry: ["setParams", "resetPage", "resetResults"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useGlobalCSS } from "./useCSS"; | |
const App = () => { | |
useGlobalCSS({ | |
"*": { | |
boxSizing: "border-box", | |
margin: 0, | |
padding: 0 | |
}, | |
ul: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To see the diagram copy this code and paste in https://statecharts.github.io/xstate-viz/ | |
const lazyPromiseMachine = Machine({ | |
id: "lazyPromise", | |
initial: "idle", | |
context: { | |
exec: () => Promise.resolve() | |
}, | |
states: { | |
idle: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You can preview it on https://statecharts.github.io/xstate-viz/ | |
const formMachine = Machine({ | |
id: "form", | |
context: { | |
initialValues: {}, | |
values: {}, | |
touched: {}, | |
errors: {}, | |
submitCount: 0, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
My Awesome Sketch | |
First State | |
some event -> Second State | |
Second State |