[CLOSED] Widget configuration question

Answered Closed
0
0

Hello team,

Another question I have is that when I create a widget, it depends on other libraries that I must preload before run init js code. Currently in my init script I use  Wisej.load([…], performLoad), but I have a feeling that there’re might be a better solution for it, is it? overriding Packages property does not help much, because it doesn’t ensure scripts will be loaded prior to init() in JS.

Also, are you planning to add following: webpack, npm support, typescript support for creating complex widgets?

 

Also, how can I add another js file (in same folder at least) to be used as part of initialisation? (let’s say after some libs loaded, I want to setup a components/modules/etc. and then use it in my init() JS code). I tried to use Wisej.load(‘anotherfile.js’, callback) or var el = document.createElement(‘script’); el.src = ‘anotherfile.js’; el.onload = callback; … etc., but it never worked and had only 404 Not Found at most.  It’s not super convenient to have all setup code in a single file

 

Please advice, as I have a feeling that it should be pretty common scenario when creating widgets. May be you can provide some existing examples that make use of these things?

 

Regards,

Michael

  • You must to post comments
Best Answer
0
0

See items below, I tried to keep the ordered 🙂

  • Widget.Packages collection is already built to guarantee the sequential loading of the resources (js and css) and it will call the init() method only after the successful loading of all packages. When you use dynamic loading (i.e. adding <script) tags, the browser loads all of the at the same time, that’s why you need a special loader to load them sequentially – which is what Wisej does already).
  • Here https://github.com/iceteagroup/wisej-extensions you will find lots of extensions that use external libraries in a very simple way: add the resources to the Packages collection. Wisej also takes care of loading the same resource only once using the name field as the key. We use the same system for very complex libraries (with hundreds of files all as embedded resources in a dll) with the entire DevExtreme, Syncfusion, KendoUI, and Infragstics set of widgets fully integrated (available for Technology Partners).
  • You can use webpack, npm or typescript with Wisej. They have nothing to do with the dynamic loading of javascript. One cleans up your references and packages the files, the other is a distribution system, the third is a javascript pre-processor that is also integrated in VS (browsers cannot use typescript). All Wisej needs is a js file. How you build it is irrelevant.
  • All Wisej controls and components (including Widget) have Call(), CallAsync(), Eval() and EvalAsync(). The Application object also has a global Call(), CallAsync(), Eval() and EvalAsync(). With Wisej the server can call the browser and the browser can call the server using [WebMethod] which also creates the equivalent js method in two flavors, adding the “Async” postfix for async method. Both Call() and Eval() take a second optional parameter that is a callback with the result since it’s obviously an async operation. Alternatively you can use await with the Async version and get the result without a callback (in reality it’s the same, but this is about the async/await compiler “trick”). https://docs.wisej.com/api/wisej.web/general/control#call-function-args and https://docs.wisej.com/api/wisej.web/general/control#callasync-function-args , etc.

Example for the last point:

private void async button1_Click(object sender, EventArgs e)
{
    var result = await EvalAsync("return 3+2;");
    AlertBox.Show(result.ToString());
}

HTH

 

 

  • You must to post comments
0
0

Also as an ER, It would be great to have in a Widget a method similar to Call(), but which returns a value of what returns called js function

 

  • You must to post comments
Showing 2 results