1export default function Shot({setComp, onReturn, flow}) { 2 3 if (typeof flow !== "function") { 4 if (typeof flow === "undefined") { 5 throw new ReferenceError("flow is undefined"); 6 } else { 7 throw new TypeError("flow must be a function"); 8 } 9 } 10 11 this.running = false; 12 this.initialize = async () => { 13 this.running = true; 14 }; 15 16 this.show = async (comp, _opts) => { 17 setComp(comp); 18 }; 19 this.reset = async () => { 20 return this.show(""); 21 }; 22 this.finalize = async () => { 23 this.running = false; 24 }; 25 26 // called by Slot.js in the component's render() 27 this.setParent = parent => { 28 console.log("setting parent to ", parent); 29 this.parent = parent; 30 }; 31 32 33 // used when the flow function exits for any reason: 34 // used to implement deferred statements. 35 this.onreturn = async () => {}; 36 37 class ResetError extends Error {} 38 this.reset = (newflow) => { 39 flow = newflow; 40 return new ResetError; 41 }; 42 43 const slot = this; 44 this.runloop = async function runloop() { 45 onReturn = onReturn || (()=>{}); 46 let err = false; 47 try { 48 const answer = await flow(slot); 49 await onReturn(answer); 50 } catch (e) { 51 if (e instanceof ResetError) { 52 setTimeout(() => runloop()); 53 return; 54 } else { 55 err = e; 56 } 57 } finally { 58 await slot.onreturn(); 59 if (err) { 60 throw err; 61 } else if (slot.running) { 62 setTimeout(() => runloop()); 63 } 64 } 65 }; 66}
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.