Friday, 30 September 2016

Dynamic updates when data changes.

Dynamic updates allow any part of the page to update itself based on change occurring  on the server.


To illustrate, begin with a simple element that display the number of assets in the system.


<div>${asset_count}</div>


In Python, the asset count would be retrieved as follows.


asset_count = server.eval(“@COUNT(example/asset)”)


When the view loads, it would process the asset count on the server side and then fill in the value in HTML.  The problem comes when someone else who is using the system adds another asset after a view has been loaded.  The data displayed is now out of date.  Normally the entire page, or in TACTIC’s case, the widget needs to be reloaded to update the correct value. However, knowing when data has changed presents a challenge.


Dynamic update solves this problem by providing a mechanism to update some part of the content based on some specified updated criteria.


For example, in the widget above, we will add an update through javascript:


<div class=”test_update”>${asset_count)</div>


In python, we would write:


kwargs[‘expr’] = “@COUNT(example/asset)”
asset_count = server.eval(kwargs.get(“expr”))


And in behaviors, we would add:


<behavior class=”test_update” event=”load”>
 var expr = kwargs.expr;
 spt.update.add( bvr.src_el, {
     expression: expr
 } );
</behavior>

This will check the expression periodically to see if the value has changed on the server.  It the value changes, such as a new asset was added, this would be detected and the value of the expression will replace what is inside the “test_update” element.  This is very useful for keeping values up to date on a page without having to refresh.


There is another argument called interval.  Normally, a dynamic update will check every couple of seconds, however, most data this is much too often.  It is possible to slow down the number of checks by setting the interval.


<behavior class=”test_update” event=”load”>
 var expr = kwargs.expr;
 spt.update.add( bvr.src_el, {
     expression: expr,
     Interval: 10,
 } );
</behavior>


This will do a check on the server about every 50 seconds.


If a widget is dependent on the values of a single SObject, then we can add search_key parameter instead and this will detect if any change to a particular SObject has been made.


<behavior class=”test_update” event=”load”>
 var search_key = bvr.kwargs.search_key;
 spt.update.add( bvr.src_el, {
     search_key: search_key,
     expression: “@GET(.status),
 } );
</behavior>


With the addition of a search_key, TACTIC will check if any changes have been made to that SObject.  If so, it will replace the “test_update” widget with the value returned from the corresponding expression.


In order to have more control, it is possible to run some javascript.


<behavior class=”test_update” event=”load”>
 var search_key = bvr.kwargs.search_key;
 spt.update.add( bvr.src_el, {
     search_key: search_key,
     cbjs_action: “spt.panel.refresh(bvr.src_el)”
 } );
</behavior>


This will update refresh the next parent refreshable widget when the corresponding SObject changes.  With a javascript callback, it is possible to do a wide variety of actions.


Finally, it is possible to attach a dynamic behavior purely in Python.


div = DivWdg()
div.add_update( {
   “expression”: expr
} )


This allows a widget that is entirely written using a Python class to make use of dynamic updates.

Dynamic updates provide a powerful and flexible means of update interface elements based on data changes on the server.  With careful judgement about what needs to be updated and how often, data viewed on a page will never be out of date.

13 comments:

  1. Nice Information Your first-class knowledge of this great job can become a suitable foundation for these people. I did some research on the subject and found that almost everyone will agree with your blog.
    Cyber Security Course in Bangalore

    ReplyDelete
  2. Writing in style and getting good compliments on the article is hard enough, to be honest, but you did it so calmly and with such a great feeling and got the job done. This item is owned with style and I give it a nice compliment. Better!
    Cyber Security Training in Bangalore

    ReplyDelete
  3. Really nice and interesting blog information shared was valuable and enjoyed reading this one. Keep posting. Thanks for sharing.
    Data Science Training in Hyderabad

    ReplyDelete

  4. Great article with unique information found useful looking forward for next blog thank you.
    typeerror nonetype object is not subscriptable

    ReplyDelete
  5. I finally found a great article here. I just added your blog to my bookmarking sites looking forward for next blog thank you.
    Data Science Course in Bangalore

    ReplyDelete
  6. I want to thank you for your efforts in writing this article. I look forward to the same best job from you in the future.

    Business Analytics Course in Bangalore

    ReplyDelete
  7. Hello! I just want to give a big thank you for the great information you have here in this post. I will probably come back to your blog soon for more information!

    Data Analytics Course in Bangalore

    ReplyDelete
  8. Fantastic blog with excellent information and valuable content just added your blog to my bookmarking sites thank for sharing.
    Data Science Course in Chennai

    ReplyDelete
  9. I really enjoy every part and have bookmarked you to see the new things you post. Well done for this excellent article. Please keep this work of the same quality.
    Artificial Intelligence course in Chennai

    ReplyDelete

  10. Thank you so much for sharing this article. I really love it. This is a very nice one and gives in-depth information. I am really happy with the quality and presentation of the article. I’d really like to appreciate the efforts you get with writing this post. Thanks for sharing.
    website: Matka Result

    ReplyDelete
  11. Thank a lot. You have done excellent job. I enjoyed your blog . Nice efforts
    Cyber Security Course in Bangalore

    ReplyDelete
  12. Nice Blog and i would like to thank for the efforts you have made in writing this post, hoping the same best work from you in the future as well. Thanks for sharing. Great websites!
    Tableau Training in Bangalore

    ReplyDelete
  13. Such a very useful article and very interesting to read this article, i would like to thank you for the efforts you had made for writing this awesome article. Thank you!
    Python Training in Bangalore

    ReplyDelete