(graphs, paths, layoutChunk, opts)
| 1268 | * See getCallbackByOutput for details. |
| 1269 | */ |
| 1270 | export function getUnfilteredLayoutCallbacks(graphs, paths, layoutChunk, opts) { |
| 1271 | const {outputsOnly, removedArrayInputsOnly, newPaths, chunkPath} = opts; |
| 1272 | const foundCbIds = {}; |
| 1273 | const callbacks = []; |
| 1274 | |
| 1275 | function addCallback(callback) { |
| 1276 | if (callback) { |
| 1277 | const foundIndex = foundCbIds[callback.resolvedId]; |
| 1278 | if (foundIndex !== undefined) { |
| 1279 | const foundCb = callbacks[foundIndex]; |
| 1280 | foundCb.changedPropIds = mergeMax( |
| 1281 | foundCb.changedPropIds, |
| 1282 | callback.changedPropIds |
| 1283 | ); |
| 1284 | if (callback.initialCall) { |
| 1285 | foundCb.initialCall = true; |
| 1286 | } |
| 1287 | } else { |
| 1288 | foundCbIds[callback.resolvedId] = callbacks.length; |
| 1289 | callbacks.push(callback); |
| 1290 | } |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | function addCallbackIfArray(idStr) { |
| 1295 | return cb => |
| 1296 | cb.getInputs(paths).some(ini => { |
| 1297 | if ( |
| 1298 | Array.isArray(ini) && |
| 1299 | ini.some(inij => stringifyId(inij.id) === idStr) |
| 1300 | ) { |
| 1301 | // This callback should trigger even with no changedProps, |
| 1302 | // since the props that changed no longer exist. |
| 1303 | // We're kind of abusing the `initialCall` flag here, it's |
| 1304 | // more like a "final call" for the removed inputs, but |
| 1305 | // this case is not subject to `prevent_initial_call`. |
| 1306 | if (flatten(cb.getOutputs(newPaths)).length) { |
| 1307 | cb.initialCall = true; |
| 1308 | cb.changedPropIds = {}; |
| 1309 | addCallback(cb); |
| 1310 | } |
| 1311 | return true; |
| 1312 | } |
| 1313 | return false; |
| 1314 | }); |
| 1315 | } |
| 1316 | |
| 1317 | function handleOneId(id, outIdCallbacks, inIdCallbacks) { |
| 1318 | if (outIdCallbacks) { |
| 1319 | for (const property in outIdCallbacks) { |
| 1320 | const cb = getCallbackByOutput(graphs, paths, id, property); |
| 1321 | if (cb) { |
| 1322 | // callbacks found in the layout by output should always run |
| 1323 | // unless specifically requested not to. |
| 1324 | // ie this is the initial call of this callback even if it's |
| 1325 | // not the page initialization but just a new layout chunk |
| 1326 | if (!cb.callback.prevent_initial_call) { |
| 1327 | cb.initialCall = true; |
no test coverage detected
searching dependent graphs…