1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    17
    Vote Rating
    0
    timbellomo is on a distinguished road

      0  

    Default Answered: Autorefresh List with DelayedTask

    Answered: Autorefresh List with DelayedTask


    I'm trying to accomplish an auto-refresh on my list using a recursive DelayedTask. I'm fairly confident that I'm running into a scope issue. I've seen a few other posts on this, but haven't seen a resolution. I've tried following the advice in those threads, but haven't been able to get it working.

    The general idea is that I'd set up the DelayedTask in the controller (control > mylist > initialize > initMyList). Using a snippet gathered from other threads:
    Code:
      initMyList: function(){
        var task = Ext.create('Ext.util.DelayedTask', function() {  
          this.getMyList().getStore().load();
          console.log("refreshed");
          task.delay(60000); //this part doesn't work
        }, this);
        task.delay(60000); //this occurrence fires correctly
      },
    I've tried declaring "task" at various other places to try to work out the scope issues, but again, haven't licked it yet. Any advice would be appreciated. Is my general approach sound? I'm not sure why, but I think this would be better than setting an individual DelayedTask on each loadMyList event.

    Thanks,
    Tim

  2. Do something like:

    Code:
    var someFunction = function() {
        var task = Ext.create('Ext.util.DelayedTask', function() {
            console.log('hi');
            someFunction.call(this);
        }, this);
    
        task.delay(2000);
    };
    
    
    someFunction();

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,227
    Answers
    3523
    Vote Rating
    859
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Do something like:

    Code:
    var someFunction = function() {
        var task = Ext.create('Ext.util.DelayedTask', function() {
            console.log('hi');
            someFunction.call(this);
        }, this);
    
        task.delay(2000);
    };
    
    
    someFunction();
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    17
    Vote Rating
    0
    timbellomo is on a distinguished road

      0  

    Default That fixed it

    That fixed it


    Thanks Mitchell - I guess my fundamentals aren't as strong as they should be.

  5. #4
    Sencha User
    Join Date
    Jun 2011
    Posts
    17
    Vote Rating
    0
    timbellomo is on a distinguished road

      0  

    Default Canceling?

    Canceling?


    How would I go about canceling the task after the fact? Basically, I have a list and a details panel. Upon view of the detail panel, I update it on an interval (using DelayedTask). When I return to the main list, I want to stop the automatic updates (at least until the next detail view is selected).

    As it stands, every new item view spawns a never ending DelayedTask. Because we defined it within a function, I'm not sure how I can access the task var to issue a task.cancel().

  6. #5
    Sencha User
    Join Date
    Jun 2011
    Posts
    17
    Vote Rating
    0
    timbellomo is on a distinguished road

      0  

    Default


    I decided to declare the var globally so I could reference it after the fact. This may be overkill, but it's working for now.

  7. #6
    Sencha User
    Join Date
    Apr 2012
    Location
    Denmark
    Posts
    71
    Answers
    1
    Vote Rating
    1
    hjeDK is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Do something like:

    Code:
    var someFunction = function() {
        var task = Ext.create('Ext.util.DelayedTask', function() {
            console.log('hi');
            someFunction.call(this);
        }, this);
    
        task.delay(2000);
    };
    
    
    someFunction();
    This worked fine for me with one delay, but how do I make it execute periodically starting from reload of the app?
    I want the task to request updates from a server every 10-15 minutes. What event do I point it at? and where?

  8. #7
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,227
    Answers
    3523
    Vote Rating
    859
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Quote Originally Posted by hjeDK View Post
    This worked fine for me with one delay, but how do I make it execute periodically starting from reload of the app?
    I want the task to request updates from a server every 10-15 minutes. What event do I point it at? and where?
    That code will keep firing every 2 seconds
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  9. #8
    Sencha User
    Join Date
    Apr 2012
    Location
    Denmark
    Posts
    71
    Answers
    1
    Vote Rating
    1
    hjeDK is on a distinguished road

      0  

    Default


    What about the event to start it?
    Sorry, I missed the .call(this) method

  10. #9
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,227
    Answers
    3523
    Vote Rating
    859
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    The painted event within the app list class would work.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  11. #10
    Sencha User
    Join Date
    Apr 2012
    Location
    Denmark
    Posts
    71
    Answers
    1
    Vote Rating
    1
    hjeDK is on a distinguished road

      0  

    Default


    So I'm trying to set up a listener for my initialize event for some component in my main view and I'm coming up short and confused. In my controller:
    Code:
    	config:{
    	    
    	    refs: 
    	    	{
    	    	    hometitle: '#hometitle',
    	    	    outdoortemp: '#outdoortemp',
    	    	    indoortemp: '#indoortemp',
    	    	}
    	},
    	
    	init: function(){
    		this.control({
    		    'button[action=showstats]':{
    		        tap: 'updateTemp',
    		    },
    
    		    '#outdoortemp':{
    		        initialize: 'updateTemp',
    		    },
    		});
    	},
    the 'updateTemp' function below this snippet has no problem accessing the label with itemId outdoortemp when I tap the button. But otherwise the function updateTemp does not get called.
    Any ideas?