not-an-aardvark / snoowrap

A JavaScript wrapper for the reddit API
MIT License
1.01k stars 125 forks source link

Make documentation examples more idiomatic #103

Open ZebTheWizard opened 7 years ago

ZebTheWizard commented 7 years ago

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)

not-an-aardvark commented 7 years ago

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.

ZebTheWizard commented 7 years ago

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

OmgImAlexis commented 3 years ago

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