1import { useState, useEffect } from 'preact/hooks'; 2 3export function useAsync(fn, deps=[], defaultValue=null) { 4 const [state, setState] = useState({ 5 value: defaultValue, 6 loading: true, 7 error: null 8 }); 9 useEffect(() => { 10 (async () => { 11 try { 12 const value = await fn(); 13 setState({value, loading: false, error: null}); 14 } catch (error) { 15 setState({value: null, loading: false, error}); 16 } 17 })(); 18 }, [fn.toString(), ...deps]); 19 20 return [state.value, state.loading, state.error]; 21} 22 23export function useEventCount(evname) { 24 const [numUpdates, setNumUpdates] = useState(0); 25 useEffect(() => { 26 function updater() { 27 setNumUpdates(prev => prev + 1); 28 } 29 window.addEventListener(evname, updater); 30 return () => { 31 window.removeEventListener(evname, updater); 32 }; 33 }, [evname]); 34 35 return [numUpdates]; 36}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.