Quellcode durchsuchen

refactoring forEach -> map

Carsten Porth vor 6 Jahren
Ursprung
Commit
e15345bed3

+ 5 - 6
app/src/providers/p2p-database-gun/p2p-database-gun.ts

@@ -48,12 +48,11 @@ export class P2pDatabaseGunProvider {
       .then();
 
     if (gunIds) {
-      const entryPromises = [];
-      Object.keys(gunIds)
-        .filter(key => key !== "_")
-        .forEach(key => entryPromises.push(this.gun.get(key).then()));
-
-      const entries = await Promise.all(entryPromises);
+      const entries = await Promise.all(
+        Object.keys(gunIds)
+          .filter(key => key !== "_")
+          .map(key => this.gun.get(key).then())
+      );
 
       return entries
         .filter(

+ 2 - 5
app/src/providers/p2p-storage-ipfs/p2p-storage-ipfs.ts

@@ -24,14 +24,11 @@ export class P2pStorageIpfsProvider {
     const options = {
       params: { arg: hash }
     };
+
     return this.http.get(this.infuraUrl + "cat", options).toPromise();
   }
 
   public async fetchTweets(hashs: string[]) {
-    const tweetPromises = [];
-    hashs.forEach(hash => {
-      tweetPromises.push(this.fetchTweet(hash));
-    });
-    return await Promise.all(tweetPromises);
+    return await Promise.all(hashs.map(hash => this.fetchTweet(hash)));
   }
 }