snoowrap icon indicating copy to clipboard operation
snoowrap copied to clipboard

Make documentation examples more idiomatic

Open ZebTheWizard opened this issue 7 years ago • 3 comments

not a big issue, but in the documentation you write your promises like this.

r.getHot({limit: 25}).then(myListing => {
  console.log(myListing.length); // => 25
  myListing.fetchMore({amount: 10}).then(extendedListing => {
    console.log(extendedListing.length); // => 35
  })
});

when it should be written like this. Otherwise you are defeating the point of promises.

r.getHot({limit: 25})
.then(myListing => {
  console.log(myListing.length); // => 25
  return myListing.fetchMore({amount: 10})
})
.then(extendedListing => {
    console.log(extendedListing.length); // => 35
});

Reference (2014)

ZebTheWizard avatar Sep 06 '17 01:09 ZebTheWizard

Thanks for the report. I agree that the code example you pointed out could be written better -- feel free to make a PR if you'd like.

not-an-aardvark avatar Sep 06 '17 01:09 not-an-aardvark

I wasn't 100% sure were I was supposed to change the code, but here is the PR.

ZebTheWizard avatar Sep 06 '17 14:09 ZebTheWizard

and now the 2021 version.

const myListing = await r.getHot({limit: 25});
console.log(myListing.length); // => 25

const extendedListing = await myListing.fetchMore({amount: 10});
console.log(extendedListing.length); // => 35

OmgImAlexis avatar Jul 24 '21 22:07 OmgImAlexis