[based on a true story]
So. Your friend's about to teach you how to make a website. Great!
You make a file, and you save it as 'index.html'. Why it's called 'index' isn't really explained to you, but whatever.
You type the following.
hello world[based on a true story]
So. Your friend's about to teach you how to make a website. Great!
You make a file, and you save it as 'index.html'. Why it's called 'index' isn't really explained to you, but whatever.
You type the following.
hello world| // The problem looks like a race condition, because I'm doing the following. isLoading can change pretty quickly | |
| {!isLoading && <AutoSizer disableWidth>{({ height }) => <div>{height}</div>}</AutoSizer>} |
| /** Async version of Array.prototype.reduce() | |
| * await reduce(['/foo', '/bar', '/baz'], async (acc, v) => { | |
| * acc[v] = await (await fetch(v)).json(); | |
| * return acc; | |
| * }, {}); | |
| */ | |
| export async function reduce(arr, fn, val, pure) { | |
| for (let i=0; i<arr.length; i++) { | |
| let v = await fn(val, arr[i], i, arr); | |
| if (pure!==false) val = v; |
| import { h, cloneElement, Component } from 'preact'; | |
| /** | |
| * <Views view="home"> | |
| * <Home name="home" /> | |
| * <Other name="other" /> | |
| * </Views> | |
| */ | |
| class Views extends Component { | |
| state = { |
| /** | |
| * Normalizes recursive VNode lists by flattening all nodes, filtering out `null` children and converting strings to | |
| * text nodes. | |
| */ | |
| export function normalizeVNodes(nodes: VNodeRecursiveList): VNode<any>[] { | |
| for (let i = 0; i < nodes.length; i++) { | |
| const n = nodes[i]; | |
| if (n === null || Array.isArray(n)) { | |
| let copy = nodes.slice(i); |
| import { h, Component } from 'preact'; | |
| /** | |
| * <SplitPoint load={require('bundle?lazy!./foo')} fallbackContent={( | |
| * <div class="loading" /> | |
| * )} /> | |
| */ | |
| class SplitPoint extends Component { | |
| componentWillMount() { | |
| let cb = this.linkState('child'), |
| function ssr(req, res, url) { | |
| let user = req.user //comes from passport | |
| const preloadedState = { user, url } // Compile an initial state | |
| const store = configureStore(preloadedState) // Create a new Redux store instance | |
| const html = render(<Provider store={store}><Html /></Provider>) // Render the component to a string | |
| const finalState = store.getState() // Grab the initial state from our Redux store | |
| res.send(renderFullPage(html, finalState)) // Send the rendered page back to the client | |
| } | |
| function renderFullPage(html, preloadedState) { |
| import { options } from 'preact'; | |
| let old = options.vnode; | |
| options.vnode = vnode => { | |
| if (!vnode.nodeName) throw Error('Undefined component'); | |
| old(vnode); | |
| }; |
| [].filter.call(document.querySelectorAll('*'), el => { | |
| if (el._component) { | |
| var p = el._priority = el.offsetHeight ? (1 - el.getBoundingClientRect().top/window.innerHeight) : -1; | |
| if (p>0) { | |
| el.setAttribute('data-priority', p); | |
| return true; | |
| } | |
| } | |
| }); |