Skip to content

Instantly share code, notes, and snippets.

@antonjb
antonjb / machine.js
Last active June 10, 2020 13:09
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@antonjb
antonjb / machine.js
Last active May 31, 2020 12:40
Generated by XState Viz: https://xstate.js.org/viz
// Idle
// after 30 seconds check status
// if in timezone && status promise resolves
// state => live
// live State
// after 30 seconds check status
// substate state == stop && outside timezone => state: idle
// substate state == play && fetch response reject => state: closing
// neither conditions pass => no op. check again in 30 seconds
// substates
export const ContentBox = createRegisterableComponent(
"content-box",
(props: { content: string }, services) => (
<div>
<p>{props.content}</p>
{services.featureState.showSpecial && (
<div>Special content item - enabled with feature toggle service</div>
)}
</div>
)
<Layout.CompositionsRenderer
services={{ featureState: { showSpecial: true } }}
compositions={[definition]}
/>
const definition = Layout.composition({
type: "site-composition",
props: {},
contentAreas: {
header: [
{
type: "site-header",
props: {
title: "Main title"
}
const Layout = new LayoutRegistration<LayoutServices>()
.registerComponents(registrar =>
registrar
.registerComponent(SiteHeader)
.registerComponent(ContentBox)
)
.registerCompositions(registrar =>
registrar
.registerComposition(SiteComposition)
.registerComposition(SplitComposition)
export const SiteComposition = createRegisterableComposition<
"header" | "content"
>()("site-composition", contentAreas => (
<div>
<header>{contentAreas.header}</header>
<main>{contentAreas.content}</main>
</div>
));
import {
getRegistrationCreators,
LayoutRegistration
} from "json-react-layouts";
const {
createRegisterableComponent,
createRegisterableComposition
} = getRegistrationCreators<LayoutServices>();
interface LayoutServices {
featureState: { showSpecial: boolean };
}
@antonjb
antonjb / component-header.tsx
Last active September 9, 2019 12:35
JSON React Layouts gists
export const SiteHeader = createRegisterableComponent(
"site-header",
(props: { title: string }, services) => (
<header>
<h1>{props.title}</h1>
</header>
)
);