I was having the same problem as you re: keeping track of handles and keeping a linear sequence of promises without nesting or chaining.
@loziniak did a good job tracking handles using objects. I souped up his code a little and it’s been working pretty well. This entire thread is probably worth reading as there are some other links.
Here’s an example using code from Loziniak’s repo (maidsafe-test/safe_api_example.html at master · loziniak/maidsafe-test · GitHub):
let app = safeAPI.initialiseApp(app_info);
app.authoriseAndConnect({_public: ['Read']});
let md = app.quickRandomPublic({'this': 'is', 'a': 'test'});
md.getString('this').then(console.log);
md.getString('a').then(console.log);
There’s a single promise chain managed in app
: all other calls and objects refer back to the promise chain in app
. Each object (app
, md
) maintains its own handle, which is also extremely convenient. A call to safeMutableData.get(mdHandle, key)
becomes md.get(key)
because the handle is stored in md
.