MCPcopy Create free account
hub / github.com/Make-md/makemd / executeCodeBlocks

Function executeCodeBlocks

src/core/utils/frames/runner.ts:273–304  ·  view source on GitHub ↗
(node: FrameNode, type: 'actions' | 'styles', codeBlockStore: FrameExecProp, results: ResultStore)

Source from the content-addressed store, hash-verified

271}
272
273function executeCodeBlocks(node: FrameNode, type: 'actions' | 'styles', codeBlockStore: FrameExecProp, results: ResultStore): ResultStore {
274 // Sort keys based on dependencies.
275 // results.state[node.id][type] = codeBlockStore
276 // Prepare an environment for executing code blocks.
277const { id } = node
278 for (const key of uniq([...Object.keys(codeBlockStore), ...Object.keys(results.newState?.[id]?.[type] ?? {})])) {
279 let result;
280 // Execute the code block.
281 try {
282 if (key in (results.newState?.[id]?.[type] || {}) && results.newState[id][type][key] !== undefined) {
283 result = results.newState[id][type][key];
284 } else {
285
286 try {
287 result = codeBlockStore[key]?.call(results.state);
288 } catch (execError) {
289 throw execError;
290 }
291 }
292 // Store the result.
293
294 if (result !== null) {
295 results.state[node.id][type][key] = result;
296 } else {
297 delete results.state[node.id][type][key];
298 }
299 } catch (error) {
300 }
301 }
302
303 return results;
304}
305

Callers 1

executeNodeFunction · 0.85

Calls 2

uniqFunction · 0.90
keysMethod · 0.80

Tested by

no test coverage detected