"use strict"; const { h, render, Component } = preact; /** @jsx h */ document.body.firstChild.remove(); const jsonParse = text => { const dateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/; function reviver(key, value) { if (typeof value === "string" && dateFormat.test(value)) { return new Date(value); } return value; } return JSON.parse(text, reviver); }; const fixupTags = result => { if (result.t.length === 1 && result.t[0] === "") { result.t.shift(); } }; const FormatDate = ({ date }) => { const display = moment.utc(date).fromNow(); const raw = date.toISOString(); return ; }; const Tags = ({ children }) => ( ); const Card = ({ link }) => (
{link.d}
by {link.a}
{link.t}

{link.n}

); class Demo extends Component { constructor(props) { super(props); this.setState({ loading: true }); } async componentDidMount() { const contents = jsonParse( await fetch("popular.json").then(res => res.text()) ); contents.forEach(fixupTags); this.setState({ loading: false, contents }); } render(props, { loading, contents }) { if (loading) { return

loading

; } return ( ); } } render(, document.body);