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

Function applyFilterChain

src/js/filter.js:5–34  ·  view source on GitHub ↗
(key, value, utils)

Source from the content-addressed store, hash-verified

3
4// loops over matching filters and passes options to each filter, returning the mapped results
5export const applyFilterChain = (key, value, utils) =>
6 new Promise((resolve, reject) => {
7 // find matching filters for this key
8 const matchingFilters = filters
9 .filter(f => f.key === key)
10 .map(f => f.cb);
11
12 // resolve now
13 if (matchingFilters.length === 0) {
14 resolve(value);
15 return;
16 }
17
18 // first filter to kick things of
19 const initialFilter = matchingFilters.shift();
20
21 // chain filters
22 matchingFilters
23 .reduce(
24 // loop over promises passing value to next promise
25 (current, next) => current.then(value => next(value, utils)),
26
27 // call initial filter, will return a promise
28 initialFilter(value, utils)
29
30 // all executed
31 )
32 .then(value => resolve(value))
33 .catch(error => reject(error));
34 });
35
36export const applyFilters = (key, value, utils) =>
37 filters.filter(f => f.key === key).map(f => f.cb(value, utils));

Callers 5

actionsFunction · 0.90
handleAddFunction · 0.90
toggleDropFunction · 0.90
toggleBrowseFunction · 0.90
togglePasteFunction · 0.90

Calls 1

nextFunction · 0.85

Tested by

no test coverage detected