Bug? [BANano] Incomplete transpilation or what I miss

Toky Olivier

Active Member
Licensed User
Longtime User
I tried to run this function (I don't want to use BANanoFetch here)
B4X:
Private Sub getTimeWait() As BANanoObject 'ignore
    Dim fetch As BANanoObject
    Dim response As BANanoPromise
    fetch.Initialize("fetch")
    response = BANano.Await(fetch.Execute(Array("http://worldtimeapi.org/api/timezone/Pacific/Noumea")))
    Return BANano.Await(response.RunMethod("text", Null))
End Sub
This is the output after transpilation:
B4X:
this.gettimewait = async function() {
    if (_B == null) _B = this;
    var _fetch, _response;
    _fetch = null;
    _response = null;
    _fetch = fetch;
    _response = await _fetch("http://worldtimeapi.org/api/timezone/Pacific/Noumea");
    return await ["text"]();
};

Why only ["text"] here not _response["text"]

Now, there is an error in the console:
B4X:
Error: ["text"] is not a function

I think the problem is in the transpilation of BANanoPromise.RunMethod as if I change to BANanoObject, It works without problem:
B4X:
Private Sub getTimeWait() As BANanoObject 'ignore
    Dim fetch As BANanoObject
    Dim response As BANanoObject
    fetch.Initialize("fetch")
    response = BANano.Await(fetch.Execute(Array("http://worldtimeapi.org/api/timezone/Pacific/Noumea")))
    Return BANano.Await(response.RunMethod("text", Null))
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
But BANanoFetch is "fetch", so Im confused as to what you want to achieve, you are just re-inventing the wheel here my friend.

Do you want to get JSON data? If so, Just call BANano.GetFileAsJson()
Do you want to get Text data?, if so, just call BANano.GetFileAsText

Sorry I cant help as Im really not clear here as to what you want to achieve, perhaps my two cents could help. ;)

Perhaps

B4X:
Sub getTimeAwait As String
dim timeX as string = banano.GetFileAsJson("http://worldtimeapi.org/api/timezone/Pacific/Noumea", null)
return timeX
End Sub
 

Toky Olivier

Active Member
Licensed User
Longtime User
Hello my friend! Yes, BANanoFetch is Fetch. And I use BANanoFetch too.
I just want to report that the transpilation of a "BANanoPromise.RunMethod" is not good for one reason I don't know.
 

Mashiane

Expert
Licensed User
Longtime User
Ok I see...

A fetch returns a promise, so your best bet it so use .Then(Text) and not .RunMethod.

I'm not very good at this promise stuff, but perhaps..

B4X:
dim Text As Object
 response = fetch.Execute(Array("http://worldtimeapi.org/api/timezone/Pacific/Noumea"))
 response.Then(text)
 response.End
 

Toky Olivier

Active Member
Licensed User
Longtime User
Yes. This works too. But as I told, I want just report that ".RunMethod" doesn't work (for some reason I don't know). Is it a bug or just one another limitation in BANano? Not that I cannot find how to use fetch or to get data from it.
Habitually, I use BANanoFetch too.
 

Mashiane

Expert
Licensed User
Longtime User
Ok, let me play along.. honestly Im not sure what you code is supposed to achieve and whether its correct or not. Anyway...

my thoughts are if "text" is a function, then runmethod will work, i.e. if on the javascript its .text();

what happens when you instead try response.getfield("text")?

on console log, what is the result of

B4X:
response = BANano.Await(fetch.Execute(Array("http://worldtimeapi.org/api/timezone/Pacific/Noumea")))

if you log it e.g. log(response)
 

alwaysbusy

Expert
Licensed User
Longtime User
I will have to look into that why it somehow lost its connection to the response variable in BANanoPromise. I honestly have never tried such a construction on the BANanoPromise object, but looking into the source code I think I see where it does go wrong. I'm not even sure the RunMethod should be in here. It is just there because it inherits from a BANanoObject, yet overrides the method. Same would happen with SetField and GetField I would expect.

This would works also:

B4X:
Private Sub getTimeWait() As BANanoObject 'ignore
    Dim fetch As BANanoObject
    Dim response As BANanoFetchResponse
    fetch.Initialize("fetch")
    response = BANano.Await(fetch.Execute(Array("http://worldtimeapi.org/api/timezone/Pacific/Noumea")))
    Return BANano.Await(response.Text)
End Sub

Of course, using the correct object BANanoFetch is the best solution.

Alwaysbusy
 

Toky Olivier

Active Member
Licensed User
Longtime User
I think I see where it does go wrong
You're the best. As always.

Thank Toky for your question, I guess I will continue and continue learning BANano. I also admit, I read the whole original post wrong, sorry about that.
It's fine, even me, I'm still learning. As I think that we can attract many developers to use BANano for Web apps and all, as soon I detect something, even if I can solve the problem in another manner, I try to ask. I'm trying to make my project with BANano so It's time for me to explore the language.
 

Mashiane

Expert
Licensed User
Longtime User
I'm trying to make my project with BANano so It's time for me to explore the language.
Awesome, it's a very powerful project thanks to Alain.

I hope one day we could use it with Node.JS, but I will cross that bridge when I get to it, the market dictates unfortunately and we have to go with the times and flow. These tools extend far beyond the forum and users here.
 

Toky Olivier

Active Member
Licensed User
Longtime User
I hope one day we could use it with Node.JS
We are not far I think. There is many thing we can do later... Yes, thank you to Alain.
You're Vue solutions are very good too. Me I'm trying to achieve with reactivity and all as with VueJS but developer may not use it and it became like traditionnal method. I'm trying to make it lighter as possible but complete as I can and easy to use... We'll see.
 
Top