I am trying to use `tinysoap` library (https://github.com/mhzed/tinysoap) in an Web AppBuilder Custom Widget.
I am able to use this library in WebAppBuilder application, as I show on the following sample code (real code included in HTML file). All my functions are included in a class called `myClass` in `customLibrary.js` file. Most functions in `customLibrary.js` call `tinysoap` functions, and everything works well:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="node_modules/tinysoap/tinysoap-browser-min.js"></script>
<script src="node_modules/lib/customLibrary.js"></script>
<script src="https://js.arcgis.com/4.15/"></script>
...
<script>
var tinySoap = this.tinysoap;
require([], function(){
//code goes here
myClass.myfunction(){...};
});
</script>Now I have to implement the same functionality in a Web AppBuilder Custom Widget.
I have had to modify javascript code from `customLibrary.js` class to `myModule.js`, and now I have this content (sample code):
# myModule.js
define([], function () {
var myModule = {};
const url = "http://example.com/wsdl?wsdl";
myModule.myFunction = function(userTxtValue, callback) {
if (userTxtValue){
console.log('1. myModule.myFunction:', userTxtValue);
var args = {name: userTxtValue};
tinySoap.createClient(url, function(err, client){
client.soapClientFunction(args, function(err, result){
return callback(result);
});
});
}
};
return myModule;
});# Widget.js
So, I have `Widget.js` file with reference to `myModule.js`, without problems, using in this way:
define(['./myModule'], function(customModule) {
customModule.myFunction( userTxtValue, function(result) {
console.log("widget.js, result:", result);
});
});Also, I have tried to insert in init.js (its is not desirable situation) but it doesn't work
dojoConfig.packages = [{
name: "widgets",
location: window.path + "widgets"
}, {
name: "jquery",
location: "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2",
main: "jquery"
}, {
name: "tinysoap",
location: window.path + "widgets/myWidget/node_modules/tinysoap/lib",
main: "soap"
},
...
}]None of these test works.
So, what is the proper way to add `tinysoap` library to my widget?
Thank you in advance !
Yes, you're totally right Shay, I have opened an issue in the repo letting them know about this situation, and if they are OK I will try to send a pull request to fix i.
BTW, I have just figured out that the problem with the "args" variable was caused by myself... ^_^'', I did a find and replace "arguments" by "args" because I was using the Grunt tasks provided by the Yeoman generator, and when it found the "arguments" variable in the code it prints out this message:
Warning: widgets/CustomTinySoap/libs/tinysoap-browser-min.js: arguments is a reserved word in strict mode (499:50)
And it doesn't copy the code to the Web AppBuilder app.
So I have reverted the changes:
Does anyone know how can I avoid that issue?, do I need to remove the "use strict" from somewhere?
UPDATE (10th August): I have opened an issue in the yeoman generator repo about this.
And I think this last thing has nothing to do with the solution, but just in case... as mentioned in my previous message, I used "jimu/loaderplugins/jquery-loader!" to load the library instead of the other ways mentioned in the developers documentation.
And I think that's all. I hope that helps.
Best regards,
Raul