From 3bc9bbcfa74a0f7454456f9bca03d3bbad44df27 Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Thu, 9 Dec 2021 12:28:06 -0800 Subject: [PATCH] Fix blog lesson 7 Two changes: - Change run so traversePosts the return value is the list not the Promise - Simplify traversePosts with the added benefit that if nothing is passed to traversePosts and empty list is returned rather than undefined. --- src/tutorials/0003-blog/07.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/tutorials/0003-blog/07.js b/src/tutorials/0003-blog/07.js index 3c2696407..b0bffd613 100644 --- a/src/tutorials/0003-blog/07.js +++ b/src/tutorials/0003-blog/07.js @@ -94,7 +94,7 @@ const run = async () => { posts: [dogPostCid] }) - return traversePosts(dogPostCid) + return await traversePosts(dogPostCid) } return run @@ -107,13 +107,9 @@ const traversePosts = async (cid) => { while (cid) { result.push(cid) const current = await ipfs.dag.get(cid) - const prev = current.value.prev - if (prev) { - cid = prev - } else { - return result - } + cid = current.value.prev } + return result } const run = async () => { @@ -151,7 +147,7 @@ const run = async () => { posts: [dogPostCid] }) - return traversePosts(dogPostCid) + return await traversePosts(dogPostCid) } return run