0

Basically, I have a couple of REST calls I need results from, and then use that result before and inside my require() call. Currently, I've instructed the REST calls ($.getJSON) to be non-async, with:

$.ajaxSetup({
    async: false
});

But, since this is not optimal, I'm wondering how the pattern looks like for them calls to be async (or rather the functions that call them).

Current (psuedo) code:

var pageConfig = getPageConfig(document); //this function calls a REST API
var appsConfig = getAppsConfig(pageConfig.appid); //this function calls another REST API

require.config( { 
    //do some stuff here with pageConfig and appsConfig
});

require( ["somelib", "jquery"], function(somelib) {
    //do some MORE stuff here with pageConfig and appsConfig
});

I know this is probably not an optimal way of doing it, so I'm looking for options.

Override
  • 258
  • 1
  • 5
  • 12
  • https://stackoverflow.com/a/41756658/2181514 – freedomn-m Nov 01 '17 at 10:03
  • 1
    You return promises from the ajax calls and continue your code with `.done(function() { ...` on that promise. – freedomn-m Nov 01 '17 at 10:05
  • See the section on promises in the top answer of the duplicate I marked. – Rory McCrossan Nov 01 '17 at 10:14
  • @freedomn-m Yeah, I'm having a hard time seeing how that would translate into having one function return data that gets passed into the second function, and then when those are done. use those results in the require() calls. – Override Nov 01 '17 at 14:01

0 Answers0