junedomingo / movieapp

Discover Movies and TV shows - React Native
MIT License
1.82k stars 473 forks source link

new Promise.all() #13

Open xilibro opened 7 years ago

xilibro commented 7 years ago
const iconsLoaded = new Promise((resolve, reject) => {
    new Promise.all(
        Object.keys(icons).map(iconName =>
        // IconName--suffix--other-suffix is just the mapping name in iconsMap
        Ionicons.getImageSource(
        iconName.replace(replaceSuffixPattern, ''),
        icons[iconName][0],
        icons[iconName][1]
        ))
    ).then(sources => {
        Object.keys(icons)
        .forEach((iconName, idx) => (iconsMap[iconName] = sources[idx]));

        // Call resolve (and we are done)
        resolve(true);
    });
});

who can help me understand why following code working: new Promise.all().then() ... i test this code in jsfiddle tell me an TypeError: Promise.all is not a constructor

Afulton11 commented 7 years ago

Probably a bit late on this, but Just use:

Promise.all

instead of

new Promise.all()

all is a static function of Promise.

Promise.all() on Mozilla docs