MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 39 lines 814 B view raw
1class ReactPromise { 2 constructor(status, value, reason) { 3 this.status = status; 4 this.value = value; 5 this.reason = reason; 6 } 7} 8 9function resolveModelChunk(chunk, value) { 10 if ("pending" !== chunk.status) { 11 chunk.reason.enqueueModel(value); 12 return; 13 } 14 15 throw new Error("unexpected pending chunk"); 16} 17 18const seen = []; 19 20function makeController() { 21 return { 22 enqueueValue(value) { 23 seen.push(`value:${value}`); 24 }, 25 enqueueModel(value) { 26 seen.push(`model:${value}`); 27 }, 28 close() { 29 seen.push("close"); 30 }, 31 error(error) { 32 seen.push(`error:${error && error.message ? error.message : String(error)}`); 33 } 34 }; 35} 36 37const chunk = new ReactPromise("fulfilled", null, makeController()); 38resolveModelChunk(chunk, "ok"); 39console.log(seen.join(","));