I’m noticing a weird behavior. I wanted to move my fetch
code to an external module to clear up my code. I created a init.js
file with the following code:
fetch("http://localhost/tsn_api/tsn.php?startup=get")
.then(function(response) {
console.log("Status: " + response.status);
return response.json();
}).then(function(json) {
json.settings.forEach(function(item) {
settings.add(item);
console.log("I'm here");
});
}).catch(function(err) {
console.log(error);
});
I added init.js
to my .unoprog
the file:
{
"RootNamespace":"",
"Packages": [
"Fuse",
"FuseJS",
"Fuse.ImageTools"
],
"Includes": [
"*",
"init.js:Bundle"
]
}
I then “required
” it inside MainView.ux
:
<JavaScript>
var Observable = require("FuseJS/Observable");
var datas = Observable();
var settings = Observable();
var myModule = require("/init.js");
module.exports = {
data: datas,
settings: settings
};
</JavaScript>
In this example the fetch
part should simply print firstly “Status…” and secondly “I’m here”. Instead it prints only “Status…”. It seems that the second .then{}
it’s not completed.
On the other hands, the above code, works correctly when I place it inside MainView.ux
as usual.
I did these testes only in Preview mode (Android). Fuse version 0.33.0 (build 10195), Win1064bit.