You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first example on the documentation reproduces callback hell which promises actually are supposed to prevent =D.
Instead of:
varclone=require("nodegit").Clone.clone;// Clone a given repository into a tmp folder.clone("git://github.com/nodegit/nodegit","tmp").then(function(repo){// Use a known commit sha from this repository.varsha="59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5";// Look up this known commit.repo.getCommit(sha).then(function(commit){// Look up a specific file within that commit.commit.getEntry("README.md").then(function(entry){// Get the blob contents from the file.entry.getBlob().then(function(blob){// Show the name, sha, and filesize in byes.console.log(entry.filename(),entry.sha(),blob.rawsize());// Show a spacer.console.log(Array(72).join("=")+"\n\n");// Show the entire file.console.log(String(blob));});});});});
you should write
varclone=require("nodegit").Clone.clone;// Clone a given repository into a tmp folder.clone("git://github.com/nodegit/nodegit","tmp").then(function(repo){// Use a known commit sha from this repository.varsha="59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5";// Look up this known commit.returnrepo.getCommit(sha)}).then(function(commit){// Look up a specific file within that commit.returncommit.getEntry("README.md")}).then(function(entry){// Get the blob contents from the file.returnentry.getBlob()}).then(function(blob){// Show the name, sha, and filesize in byes.console.log(entry.filename(),entry.sha(),blob.rawsize());// Show a spacer.console.log(Array(72).join("=")+"\n\n");// Show the entire file.console.log(String(blob));});
Thanks for letting us know! We're currently in the process of redoing our website and as you can tell from our README we're already using a better Promise chain approach.
Activity
tbranyen commentedon Feb 15, 2015
Thanks for letting us know! We're currently in the process of redoing our website and as you can tell from our README we're already using a better Promise chain approach.