1 Reply Latest reply on Jan 17, 2018 1:35 PM by dclayworth RSS
    dclayworth Apprentice

    Services on Widgets

    I understand from browsing the source that you can define services on widgets. Is there any documentation, or specific examples, on how to do this?


    Part of the thinking behind this is that I want to be able to do simple transformations on data as it is passed from one widget to another. If I write a service on a Thing to do the transformation, then the data has to go back to the server, be transformed, and then come back to the client. If I can somehow write a service that lives on the client then I can avoid this. Am I on the right track for how I should do this?

      • Re: Services on Widgets
        philh Newbie

        That's a perfectly reasonable approach.  You may be able to accomplish it with the expression widget if it's a simple enough transformation.  But presuming you need to do it within a widget, it's very straightforward.


        One example you can see in the combined js source is the navigation widget.


        In the ide.js portion of your widget, declare the service like this:

        this.widgetServices = function () {

          return {

          'Navigate': { 'warnIfNotBound': false }




        In the runtime.js of your widget

        this.serviceInvoked = function (serviceName) {

          var widgetReference = this;

          if (serviceName === 'Navigate') {

            // your code here!

          } else {

          TW.log.error('Navigation widget, unexpected serviceName invoked "' + serviceName + '"');




        Other notes:

        You will need to declare the various properties that you'll be using for your calculations, as services on widgets do not take parameters.   The slider widget provides a good example of this as well.