MCPcopy Index your code
hub / github.com/microsoft/SandDance / respondToRequest

Function respondToRequest

packages/sanddance-embed/src/sanddance-embed.ts:53–96  ·  view source on GitHub ↗
(requestWithSource: MessageRequestWithSource)

Source from the content-addressed store, hash-verified

51 }
52
53 export function respondToRequest(requestWithSource: MessageRequestWithSource) {
54 requests.push(requestWithSource);
55 const copy: MessageRequestWithSource = { ...requestWithSource };
56 delete copy.source;
57 const request: MessageRequest = { ...copy };
58 let response: MessageResponse;
59 switch (request.action) {
60 case 'init': {
61 response = {
62 request,
63 };
64 break;
65 }
66 case 'load': {
67 const request_load = request as MessageRequest_Load;
68 load(request_load.data, request_load.insight).then(() => {
69 response = {
70 request,
71 };
72 requestWithSource.source.postMessage(response, '*');
73 });
74 //don't keep a copy of the array
75 delete request_load.data;
76 break;
77 }
78 case 'getData': {
79 response = <MessageResponse_GetData>{
80 request,
81 data: sandDanceExplorer.state.dataContent.data,
82 };
83 break;
84 }
85 case 'getInsight': {
86 response = <MessageResponse_GetInsight>{
87 request,
88 insight: sandDanceExplorer.viewer.getInsight(),
89 };
90 break;
91 }
92 }
93 if (response) {
94 requestWithSource.source.postMessage(response, '*');
95 }
96 }
97
98 window.addEventListener('message', e => {
99 let payload: object[] | DataWithInsight | MessageRequest = e.data;

Callers 1

sanddance-embed.tsFile · 0.85

Calls 3

loadFunction · 0.70
postMessageMethod · 0.65
getInsightMethod · 0.45

Tested by

no test coverage detected