B4J Question Basic questions about B4JS

B4JExplorer

Active Member
Licensed User
Longtime User
Hi,

I'd like to play around with B4JS, but don't understand how it compiles to Javascript, and what library to use.

At what point does the compilation to Javascript take place?

Do we have any sample projects to play with? It's done inside the B4J ide, correct?

I think someone asked if it could be done outside of an ABM context. Can it also be used outside of a B4J context, with existing html5?

Sorry, but I'm totally confused after scanning the 7 tutorials. The code is clear enough, but I'm not sure how to actually use it.


Regards,
 

alwaysbusy

Expert
Licensed User
Longtime User
B4JS is an extension of ABMaterial: it is is used for e.g. checking the validity of the value of an input field. It is mostly used with ABMaterial components. If you are not using ABMaterial, then B4JS is not useful. 90%+ of a WebApp in ABMaterial is done on the server side.

According to your questions, you may hava a look at my new library BANano, which started as an extraction of B4JS from ABMaterial so it can work without ABMaterial; https://www.b4x.com/android/forum/threads/banano-progressive-web-app-library.99740/. It has outgrown ABMaterials B4JS in the last few weeks to a full blown B4J code to Javascript transpiler. Maybe reading the introduction may help in understanding the difference between the two.

Therefor, it makes more sense for me to give the answers in this BANano context (whenever I use the term app, you can think website too, and visa versa):

At what point does the compilation to Javascript take place?
EVERYTHING you write in the the B4J IDE (except the AppStart and Application_Error methods) is translated to Javascript. I mean, every class or module you write in the B4J IDE. This 'compilation' happens once when you run your B4J app: the BANano.Build() method you write in AppStart() generates all the JavaScript, some basic HTML to start the app/website with and copies your css and assets (e.g. images you loaded in the B4J IDE under Files). After that point, it does not need your B4J code anymore to run. Just open the generated HTML file, and your app/website will work, completely stand-alone.

Do we have any sample projects to play with?
BANano is only a few weeks old, so not that many. In the zip there is a demo app, which is actually my app to test the translation from B4J source code to JavaScript. Therefor, it is not a beautiful looking thing but the source code shows a lot on how things are done. You will see it shares its syntax with B4J. You will have to open up the browsers console (Chrome, F12) as most of its output happens there.

Kiffi has already written a BANano library (which is basically the same as writing a BANano app, except it uses B4J 'compile to library' so you can re-use the code in another BANano project) which may show you how to incorporate an existing Javascript framework: https://www.b4x.com/android/forum/threads/banano-leaflet-wrapper.100389 and a real life demo of it on his server: http://banano.tuebben.de/leaflet/demo/. This last demo does run without any VPS (a thing ABMaterial does need, as it needs to run the jar).

It's done inside the B4J ide, correct?
Yes, all programming is done within the IDE.

Can it also be used outside of a B4J context, with existing html5?
You can use the BANano.Initialbody parameter to fill BANano's starting HTML5 <body> tag. It can be any html. From there on, you can use the BANanoElement and BANanoObject to manipulate these tags. Of course, you can also use BANano's own functions to add html at run time.

Do a search on the forum for 'BANano' and all of this will make more sense as this is to big to explain in one post. It also gives answers to some questions like how to make an Ajax call, or how to connect it with a B4J server, etc... If, after reading, you do have a specific question, use [BANano] in the subject,. I'll do my best to answer it.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Yes, Banano is indeed what I was looking for.

Thanks for the link and all the detail.

One minor question - Are Private declarations supported? I noticed in the Intro the translations were from Dims.


Thanks, Alain.
 
Upvote 0
Top