MCPcopy
hub / github.com/pqina/filepond / handleAdd

Function handleAdd

src/js/app/actions.js:474–532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

472
473 item.on('load', () => {
474 const handleAdd = shouldAdd => {
475 // no should not add this file
476 if (!shouldAdd) {
477 dispatch('REMOVE_ITEM', {
478 query: id,
479 });
480 return;
481 }
482
483 // now interested in metadata updates
484 item.on('metadata-update', change => {
485 dispatch('DID_UPDATE_ITEM_METADATA', { id, change });
486 });
487
488 // let plugins decide if the output data should be prepared at this point
489 // means we'll do this and wait for idle state
490 applyFilterChain('SHOULD_PREPARE_OUTPUT', false, { item, query }).then(
491 shouldPrepareOutput => {
492 // plugins determined the output data should be prepared (or not), can be adjusted with beforePrepareOutput hook
493 const beforePrepareFile = query('GET_BEFORE_PREPARE_FILE');
494 if (beforePrepareFile)
495 shouldPrepareOutput = beforePrepareFile(item, shouldPrepareOutput);
496
497 const loadComplete = () => {
498 dispatch('COMPLETE_LOAD_ITEM', {
499 query: id,
500 item,
501 data: {
502 source,
503 success,
504 },
505 });
506
507 listUpdated(dispatch, state);
508 };
509
510 // exit
511 if (shouldPrepareOutput) {
512 // wait for idle state and then run PREPARE_OUTPUT
513 dispatch(
514 'REQUEST_PREPARE_OUTPUT',
515 {
516 query: id,
517 item,
518 success: file => {
519 dispatch('DID_PREPARE_OUTPUT', { id, file });
520 loadComplete();
521 },
522 },
523 true
524 );
525
526 return;
527 }
528
529 loadComplete();
530 }
531 );

Callers 1

actionsFunction · 0.85

Calls 4

applyFilterChainFunction · 0.90
queryFunction · 0.85
loadCompleteFunction · 0.85
dispatchFunction · 0.50

Tested by

no test coverage detected