0

Timer callback function and global functions

Hallo *,

may be a simple question...
I would like to call a function named "_test()" in a callback function of a timer.
Unfortunately I get an error: "this function is not a function"!

Calling the function "_test()" directly in "createView" works well.

Thanks for any hints!


CODE
var MainView = new KONtx.Class({
ClassName: 'MyCustomMainView',

Extends: KONtx.system.SidebarView,

initialize: function(){

}

createView: function() {

// timer blog begin
var when = 5000;
var myTimer =(periodic) ? KONtx.utility.timer.setInterval( function(){

var x = this._test(); // ERROR -> this function is not a function!
log(x);


}, when) : KONtx.utility.timer.setInterval(function(){ KONtx.utility.timer.clearTimeout(myTimer);},when);
// timer blog end


var y = this._test(); //calling the _test function works well!
log(y);



}

updateView: function(){

}

_test: function(){
return "Test OK";
}

}); //MainView End

by
19 Replies
  • 1)
    In the callback function ein tried:

    MainView ._test();
    -> Error the function is not a function

    2)
    I tried to pass the "MainView" as argument to the callback function (code below).
    -> Error the function is not a function

    CODE
    var MainView = new KONtx.Class({
    ClassName: 'MyCustomMainView',

    Extends: KONtx.system.SidebarView,

    initialize: function(){

    }

    createView: function() {

    // timer blog begin
    var when = 5000;

    var myTimer =KONtx.utility.timer.setInterval( function(x){ //Timer Function more simple

    var y = x._test(); // ERROR -> this function is not a function!
    log(y);


    }, when, Mainview);
    // timer blog end


    var x = this._test(); //calling the _test function works well!
    log(x);



    }

    updateView: function(){

    }

    _test: function(){
    return "Test OK";
    }

    }); //MainView End

    [/quote]
    0
  • Can someone explain to me the proper way how to update the UI every 5 seconds?
    for example fetching a xml file every 5 seconds and update e.g. a KONtx.element.Text element with information of the xml file?

    I tried someting like that with no success:

    I start a timer in my e.g. updateView function.

    var myTimer = KONtx.utility.timer.setInterval(this._test, 5000);

    my _test() function is executed every 5 seconds, fine.
    Is it possible to pass a grid control, defined in CreateView() to a callback function of a timer to update the grid dataset?

    var myTimer = KONtx.utility.timer.setInterval(this._test, 5000, myGrid);

    _test: function(GridControl){

    // get xml parse it and do someting ... and build an array...
    var arr=[];
    arr.push({});
    arr.push({});
    ...
    arr.push({});

    // now pass the new arr to the Grid.
    GridControl.changeDataset(arr )
    }

    I assume this is not the right way to update the UI.

    Thanks a lot.
    oliver
    0
  • Hi Oliver,

    I can help you the following:
    1. Please add var controller = this; into first line of createView function, then change this to controller.
    2. var myTimer = KONtx.utility.timer.setInterval(this._test, 5000, myGrid);

    _test: function(GridControl){

    // get xml parse it and do someting ... and build an array...
    var arr=[];
    arr.push({});
    arr.push({});
    ...
    arr.push({});

    // now pass the new arr to the Grid.
    GridControl.changeDataset(arr )
    }

    Did your myGrid use the property cellUpdater? If yes, then it update automatically when you called GridControl.changeDataset(arr );

    Thanks,
    Hoa Tat.
    0
  • QUOTE (tatquanghoa @ Aug 26 2009, 07:20 PM) <{POST_SNAPBACK}>
    Hi Oliver,

    I can help you the following:
    1. Please add var controller = this; into first line of createView function, then change this to controller.
    2. var myTimer = KONtx.utility.timer.setInterval(this._test, 5000, myGrid);

    _test: function(GridControl){

    // get xml parse it and do someting ... and build an array...
    var arr=[];
    arr.push({});
    arr.push({});
    ...
    arr.push({});

    // now pass the new arr to the Grid.
    GridControl.changeDataset(arr )
    }

    Did your myGrid use the property cellUpdater? If yes, then it update automatically when you called GridControl.changeDataset(arr );

    Thanks,
    Hoa Tat.



    Hallo Hoa Tat,
    thanks for your reply.

    I already tried something like " var controler = this;" in the beginning of my code / my functions.
    Further on, using controler instead of this leads into other problems... :-/
    e.g. unfortunatelyI I run into redering errors. Some parts of my widget always remained "black".

    Yes, I use cellCreater and cellUpdater. For today i will investigate my ui update problem closer.
    I have some more options/ideas to test...

    thanks
    oliver
    0
  • My
    FRAMEWORK Version is 1.1.44
    WC-WDK Version is 0.9.6-19
    0
  • I sure hope you're not making a server request every 5 seconds oliver. I doubt that Yahoo! will approve anything that consumes that much network traffic (even if it's just small bits of data).
    0
  • QUOTE (Mike @ Aug 27 2009, 10:04 AM) <{POST_SNAPBACK}>
    I sure hope you're not making a server request every 5 seconds oliver. I doubt that Yahoo! will approve anything that consumes that much network traffic (even if it's just small bits of data).



    HI Mike,

    first i have to say , i solved my problöems updating the UI.
    I do it exactly like it is done in the finance examplewidget.
    KONtx.message.store , .fetch and eventing is my friend :-)

    Ok back to your apprehension, Mike.
    Yes, in the moment (first step) i need a such data polling. this is for a showcase only ;-)

    In the next step a local working deamon (on a ce3100 plattform) will get all the news/changes due to a publish subscribe model.
    so my wiget polls from localhost ;-)
    0
  • Hi Oliver,

    My #1 solved your error. Error "black" can be other error. Please give me some information clearly.
    I please give you a example and think that it can help in timer.

    // set timer for back ground information
    this.textRunTimer = new Timer();
    this.textRunTimer.ticking = true;
    //set time interval
    this.textRunTimer.interval = 10.0;
    this.textRunTimer.onTimerFired = this.timerMessager;

    timerScreensaver: function() {
    log('******************* good *******************');
    },

    Thanks and Regards,
    Hoa Tat.
    0
  • Hi Oliver,

    Let refer to my code in your case:
    CODE
    createView: function() {
    this.controls.myGrid = new Grid.....;//your code
    this.controls.timer = KONtx.utility.timer.setInterval(this._test, 5000);
    this.controls.timer.myGrid = this.controls.myGrid;
    },
    updateView: function() {
    //your code
    },
    _test: function() {
    // get xml parse it and do someting ... and build an array...
    var arr=[];
    arr.push({});
    arr.push({});
    ...
    arr.push({});

    // now pass the new arr to the Grid.
    this.myGrid.changeDataset(arr);//this: timer, not view
    }


    Note:
    1.the function parameter is a function has no parameter.
    2. in the function when timer executes, "this" refer to timer.

    Good luck, Oliver.
    0
  • QUOTE (Mike @ Aug 27 2009, 10:04 AM) <{POST_SNAPBACK}>
    I sure hope you're not making a server request every 5 seconds oliver. I doubt that Yahoo! will approve anything that consumes that much network traffic (even if it's just small bits of data).



    Mike is correct, anything with that fast a polling rate will not be allowed. Even without the network traffic issue, it creates a poor UI experience for the user. Trust me, I wrote the Finance widget so I know. :P-Jeremy
    0
  • QUOTE (Jeremy Johnstone @ Aug 31 2009, 09:18 AM) <{POST_SNAPBACK}>
    Mike is correct, anything with that fast a polling rate will not be allowed. Even without the network traffic issue, it creates a poor UI experience for the user. Trust me, I wrote the Finance widget so I know. :PWhat would an acceptable polling rate be?
    0
  • QUOTE (stevelaw1981 @ Sep 3 2009, 09:01 AM) <{POST_SNAPBACK}>
    What would an acceptable polling rate be?


    Depends on what you are doing on screen at the time. In general, anything faster than once every 60-120s when your widget is actively being used is about the limit.

    -Jeremy
    0
  • QUOTE (stevelaw1981 @ Sep 3 2009, 09:01 AM) <{POST_SNAPBACK}>
    What would an acceptable polling rate be?


    Depends on what you are doing on screen at the time. In general, anything faster than once every 60-120s when your widget is actively being used is about the limit.

    -Jeremy
    0
  • QUOTE (Oliver @ Aug 27 2009, 01:20 PM) <{POST_SNAPBACK}>
    HI Mike,

    first i have to say , i solved my problöems updating the UI.
    I do it exactly like it is done in the finance examplewidget.
    KONtx.message.store , .fetch and eventing is my friend :-)

    Ok back to your apprehension, Mike.
    Yes, in the moment (first step) i need a such data polling. this is for a showcase only ;-)

    In the next step a local working deamon (on a ce3100 plattform) will get all the news/changes due to a publish subscribe model.
    so my wiget polls from localhost ;-)



    Where did you find the finance examplewidget for TV? I would like to have a look on it in order to catch good practices and ui components use. I have finance for Windows PC but not for connected TV. I haven't yet a TV so i am using only simulator at this moment

    Thanks
    Jorge
    0
  • QUOTE (jorgegarciallorente @ Jan 5 2010, 07:38 AM) <{POST_SNAPBACK}>
    Where did you find the finance examplewidget for TV? I would like to have a look on it in order to catch good practices and ui components use. I have finance for Windows PC but not for connected TV. I haven't yet a TV so i am using only simulator at this moment

    Thanks
    Jorge

    The source code is no longer available. Earlier simulators contained the Finance, News, Weather, etc widgets so the source code was able to be viewed. However, Yahoo decided to prevent access to the source code of those widgets.
    0
  • QUOTE (jorgegarciallorente @ Jan 5 2010, 07:38 AM) <{POST_SNAPBACK}>
    Where did you find the finance examplewidget for TV? I would like to have a look on it in order to catch good practices and ui components use. I have finance for Windows PC but not for connected TV. I haven't yet a TV so i am using only simulator at this moment


    They were pulled as they aren't being updated frequently anymore and subsequently aren't the best examples of good practices anymore. We will have many new examples very soon.

    -Jeremy
    0
  • I'm just curious, why would polling more than once per minute to an external URL (say to get a status indicator) be considered unacceptable but streaming video content is considered acceptable? I would think the former could be done with very minimal data transfer, just 1-2K per minute whereas the streaming video would be a few orders of magnitude higher in terms of network bandwidth.

    I'm new to developing with the WDK (but I've developed STB software for a while), so forgive me in advance if I'm missing something for being green :)
    0
  • QUOTE (Les C @ Mar 3 2010, 10:16 AM) <{POST_SNAPBACK}>
    I'm just curious, why would polling more than once per minute to an external URL (say to get a status indicator) be considered unacceptable but streaming video content is considered acceptable? I would think the former could be done with very minimal data transfer, just 1-2K per minute whereas the streaming video would be a few orders of magnitude higher in terms of network bandwidth.

    I'm new to developing with the WDK (but I've developed STB software for a while), so forgive me in advance if I'm missing something for being green :)The video has nothing to do with the polling as that is played using a different mechanism.
    0
  • Ah makes sense, I wasn't aware that the JS engine was single threaded. Thanks Steve.
    0

Recent Posts

in General - Yahoo! TV Widgets