Specify your routes with paths and corresponding components
const routes = [
| // Copy this into the browser console | |
| let _=i=$D=1;Object.defineProperty(this,'mood',{set(){console.log(`Made ${i++} folks happy!`);Math.random()<.1&&(_=0)}}) | |
| // Then you can do this and find out how many people you made happy :) | |
| please: for (;_;) mood = $D |
I hereby claim:
To claim this, I am signing this object:
| // Shortest (96 chars): | |
| Number.prototype[Symbol.iterator]=function(){let i=0;return{next:()=>({done:i>this,value:i++})}} | |
| // Only return value if not done yet (112 chars): | |
| Number.prototype[Symbol.iterator]=function(){let i=0;return{next:()=>({done:i>this,...!(i>this)&&{value:i++}})}} | |
| // Readable: | |
| Number.prototype[Symbol.iterator] = function() { | |
| let i = 0; |
| const isPlainObject = object => Object.prototype.toString.call(object) === '[object Object]' | |
| const recursiveAssign = (target, ...sources) => { | |
| sources.forEach(source => { | |
| Object.entries(source).forEach(([key, value]) => { | |
| if (isPlainObject(target[key]) && isPlainObject(value)) recursiveAssign(target[key], value) | |
| else target[key] = value | |
| }) | |
| }) | |
| return target | |
| } |
| // Loading "smoothscroll-polyfill" & "smoothscroll-anchor-polyfill" + setting scroll-behavior to smooth in 247 bytes: | |
| ((d,s,u)=>{d.documentElement.setAttribute('style','scroll-behavior:smooth');let i=s=>{let e=d.createElement('script');e.src=s;d.head.append(e)};i(u+s+`-polyfill/dist/${s}.min.js`);i(u+s+'-anchor-polyfill')})(document,'smoothscroll','//unpkg.com/') | |
| // Readable version: | |
| ((doc, name, cdn) => { | |
| // Set scroll-behavior, setAttribute so it works in browsers that don't recognize the property | |
| doc.documentElement.setAttribute('style', 'scroll-behavior: smooth;'); | |
| // Function to insert scripts... | |
| const insertScript = url => { | |
| const scriptElement = doc.createElement('script'); |
| /* Used to extract a from a Swagger API spec */ | |
| function generateTypeScriptInterface(targetDef, definitions) { | |
| if (typeof targetDef === 'string') { | |
| definitions = | |
| definitions || | |
| window.__defs__ || | |
| (window.__defs__ = JSON.parse(document.querySelector('body pre').textContent).definitions); | |
| targetDef = definitions[targetDef]; | |
| } |
| import React, { useState, useEffect, useCallback } from 'react' | |
| export const IDLE = 'IDLE' | |
| export const LOADING = 'LOADING' | |
| export const SUCCESS = 'SUCCESS' | |
| export const ERROR = 'ERROR' | |
| export function useAsyncData(fetchFn, deps) { | |
| const stableFetchFn = useCallback(fetchFn, deps) | |
| const [{ state, data, error }, setState] = useState({ state: IDLE }) |