(node: FrameNode, type: 'actions' | 'styles', codeBlockStore: FrameExecProp, results: ResultStore)
| 271 | } |
| 272 | |
| 273 | function 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. |
| 277 | const { 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 |
no test coverage detected