import { async, Async } from '../../src/runtime/async' /** * Returns a promise that resolves after `n` milliseconds. */ function wait(n: number): Promise { return new Promise((resolve) => setTimeout(resolve, n)) } /** * A component that takes properties synchronously, and asynchronously returns * an element. */ const FirstAsyncMessage = async(({ message, timeout }: { message: string, timeout: number }) => ( wait(timeout).then(() => (

{message}

)) )) /** * Ditto, but with a different syntax. */ const SecondAsyncMessage = ({ onFriday, onOtherDay }: { onFriday: string, onOtherDay: string }) => async( wait(2000).then(() => { const day = new Date().getDay() if (day == 5) return {onFriday} else return {onOtherDay} }) ) /** * A promise that resolves to a component, used with the `` component. */ const ThirdAsyncMessage = wait(3000).then(() => ({ message }: { message: string }) => (

{message}

)) /** * A component whose properties will be resolved asynchronously, * used with the `` component. */ const FourthAsyncMessage = ({ message, bold }: { message: string, bold: boolean }) => ( bold ? {message} :

{message}

) document.body.appendChild(
({ message: 'And so am I!' }))} bold={true} />
)