MCPcopy
hub / github.com/single-spa/single-spa / flattenFnArray

Function flattenFnArray

src/lifecycles/lifecycle.helpers.js:15–45  ·  view source on GitHub ↗
(appOrParcel, lifecycle)

Source from the content-addressed store, hash-verified

13}
14
15export function flattenFnArray(appOrParcel, lifecycle) {
16 let fns = appOrParcel[lifecycle] || [];
17 fns = Array.isArray(fns) ? fns : [fns];
18 if (fns.length === 0) {
19 fns = [() => Promise.resolve()];
20 }
21
22 const type = objectType(appOrParcel);
23 const name = toName(appOrParcel);
24
25 return function (props) {
26 return fns.reduce((resultPromise, fn, index) => {
27 return resultPromise.then(() => {
28 const thisPromise = fn(props);
29 return smellsLikeAPromise(thisPromise)
30 ? thisPromise
31 : Promise.reject(
32 formatErrorMessage(
33 15,
34 __DEV__ &&
35 `Within ${type} ${name}, the lifecycle function ${lifecycle} at array index ${index} did not return a promise`,
36 type,
37 name,
38 lifecycle,
39 index
40 )
41 );
42 });
43 }, Promise.resolve());
44 };
45}
46
47export function smellsLikeAPromise(promise) {
48 return (

Callers 2

mountParcelFunction · 0.90
toLoadPromiseFunction · 0.90

Calls 4

objectTypeFunction · 0.90
toNameFunction · 0.90
formatErrorMessageFunction · 0.90
smellsLikeAPromiseFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…