how to call a JSView from an XSJS file? - sapui5

I know I can call other JS files from XSJS by making a .xsjslib file. I would like to be able to call a JSView instead. Is this possible?
Note: the reason for me to this is that I can then use the SAPUI5 libraries and make it easier to import external libraries to my code. This is more of general question than trying to target a specific problem.

that's not possible, as the UI5 JSView is in the front end and XSJS is server-side code. Cheers

Related

Simple API call within the context of DocFx preprocessor

I would like to know if it is possible to make a simple API call (e.g. GitHub API v3) within the context of a DocFx custom template preprocessor. I have been trying all sorts of different approaches, but nothing has fully worked so far.
My goal is to make a call to an API to retrieve some data, and then update the model accordingly to be used in the *.liquid or *.tmpl renderers.
I have tried using the http/https node modules. I have also tried using node-fetch. It results in a docfx build error something like:
Error:Error transforming model ".../index.raw.json" generated from
".../index.md" using "conceptual.html.primary.js". Error running
Transform function inside template preprocessor
According to DocFx documentation, preprocessors follow the ES 5.1 standard. My code conforms to this.
Does anyone know if this is possible?
By the way, I am able to do simple model manipulation just fine, so I understand the basic concepts here with the DocFx preprocessors.
Thanks!
For the benefit of others, I discovered DocFX uses jint which cannot require a Node library directly. Therefore, it appears the plugin route is a better way to go for this use case.

How do I unload a module from Bing Maps?

Assume I have loaded a module like auto-suggest like,
Microsoft.Maps.loadModule('Microsoft.Maps.AutoSuggest', callback);
Is there any way available to unload this module? Thanks in advance.
No, but there is no need to. Loading it simply downloads the script needed for that part of the API. It's like loading any other JavaScript file into your application, once downloaded, there is no undownloading it.

can there be two js files in main dir of mozilla addon? and can they both communicate with each other?

I have created two separate add ons. One for getting input from the user and storing in simple-storage. In the other one the actual add on function. Both work fine. But when i merge these both main add on code in to a single main code they didn't work. So i wonder whether there can be two js files in "main" add on directory and is communication possible between them?I need one of the js in main directory to be able to access the simple-storage of the other js in the same main directory.
I'm really not sure what your overall goal is, please provide an example for a more specific answer. If you're using the Add-on SDK, only code in main.js will be run, but you can use commonJS modules to implement various features and use require to import them into main.js.
Please see the docs for more information on how the Add-on SDK works:
https://developer.mozilla.org/en-US/Add-ons/SDK

how to load external libraries into an SAPUI5 view?

In SAPUI5 I can load local files this way:
jQuery.sap.require("util.someFile");
But is it possible to load external libraries when required in some view using the above command or a similar approach? Ideally, I am looking for something like:
theLoadingCommand("some_url");
Thanks
Basically it is possible to register a module path to some URL.
jQuery.sap.registerModulePath('external.library', 'http://....'); //not working
There is only one problem with that. UI5 loads the resources via AJAX requests. Your browser will give you an error because you are trying to load files from a different host.
You can include external libraries by including the file in a normal script tag. It is also possible to include requireJS in your project and use its features. Unfortunately, at the moment UI5 doesn't support requireJS out of the box.
jQuery is supported by SAPUI5, so you can extend your heading from controller, for example:
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "http://somedomain.com/somescript";
$("head").append(s);

How do I write an extension for Sinatra without packaging it as a gem?

I want to include the distance_of_time_in_words method in a sinatra app
I don't want to package and distribute a gem, which is what the Sintra docs direct you to do. I just want that method accessible in my view.
What's the easiest way to do this? Thanks.
On http://www.sinatrarb.com/intro.html look at Helpers section and define helper methods for use in route handlers and templates
Just place the file somewhere in your ruby load path ($LOAD_PATH) and require it. Or place the code directly in your app file.