I'm having issues rebuilding my app with requirejs.
Previous code:
function getData(){
chrome.storage.local.get('settings',function(object){
var stored_data = object;
settings = stored_data['settings'];
//do something with settings object
createFromSettings(settings);
});
}
getData();
With Requirejs (2 modules):
config.js:
requirejs.config({
baseUrl: '../src/js/modules',
paths: {
settings: 'getSettings',
create_elements: 'createElements'
}
getSettings.js
define(function(){
function localSettings(callback){
chrome.storage.local.get('settings',function(object){//async
var stored_data = object;
settings = stored_data['settings'];
callback(settings)
})
}
return{
getSettings:localSettings(function(data){
console.log(data)
//data is ok here
})
}
})
and in createElements.js
define(['settings'],function(settings){
console.log(settings.getSettings)
//returns undefined
})
But it doesn't work because I cannot use return in async. I cannot understand how to use the result (settings) in createElements.js module.
Thanks!