1. #1
    Sencha User
    Join Date
    Jun 2013
    Location
    Rennes, France
    Posts
    3
    Vote Rating
    0
    Kelenn is on a distinguished road

      0  

    Default Repeated tasks using Ext.util.DelayedTask

    Repeated tasks using Ext.util.DelayedTask


    Hello !

    I'm trying to use Ext.util.DelayedTask to do a repeated task like setInterval does.
    My following code works into the initialize function of an Ext.container :

    Code:
    var task = new Ext.util.DelayedTask(function(active) {               
                    home_controller.RefreshAlarmsCount();
                    this.fireEvent("TaskEnded");
                }, this),
                refreshAlarms = function(active) {
                    if (active) {
                        task.delay(1000);
                        this.on('TaskEnded', task);
                    } else if (!active) {
                        if (this.hasListener('TaskEnded')){
                            this.removeListener('TaskEnded');
                        }
                        task.cancel();
                    }
                };
    
    this.on('show', function() {
                refreshAlarms(true);
            });
            this.on('hide', function(){
                refreshAlarms(false);
            }),
    But each time the fireEvent is fired, I get this error message into Chrome's console :

    Uncaught TypeError: Object [object Object] has no method 'apply'
    Ext.define.doFire
    Ext.define.fire
    Ext.define.doDispatchEvent
    Ext.define.dispatchEvent
    Ext.define.doFireEvent
    Ext.define.fireEvent
    (anonymous function)
    call

    However, the task is repeating and is cancelling like I expected.
    Am I doing something wrong or is it a bug ?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Vote Rating
    827
    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


    An error like that usually means you have a scope issue that it's not the scope you think it is.
    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.

  3. #3
    Sencha User
    Join Date
    Jun 2013
    Location
    Rennes, France
    Posts
    3
    Vote Rating
    0
    Kelenn is on a distinguished road

      0  

    Default


    Thank you for the reply.

    When I do "console.log" on the two following variables (containerOne, containerBis), I have my container with "id: "home-page"".

    Code:
    Ext.define('HomePage', {
        extend: 'Ext.Container',
        
        config: {
            id: 'home-page',
            scrollable: {
                direction: 'vertical',
                directionLock: true
            },
            items: []
        },
        
        initialize: function() {
            var   containerOne = this,
                  containerBis = Ext.get('home-page'),
    
                  task = new Ext.util.DelayedTask(function(active) {
                      console.log("test");
                      containerOne.fireEvent("TaskEnded");
                  }, containerOne),
    
                  refreshAlarms = function(active) {
                      if (active) {
                          task.delay(1000);
                          containerOne.on('TaskEnded', task);
                      } else if (!active) {
                          if (containerOne.hasListener('TaskEnded')){
                              containerOne.removeListener('TaskEnded');
                          }
                          task.cancel();
                      }
                  };
    
            console.log(containerOne);
            console.log(containerBis);
        }
    });
    I tried passing those two variables into the scope argument of the DelayedTask constructor.

    I have the same problem, my event is fired and chrome's console displays the error I described in my first post.

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Vote Rating
    827
    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


    First thing I see right away with your code is you are overriding the initialize method but not calling the parent which will break inheritance.
    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.

  5. #5
    Sencha User
    Join Date
    Jun 2013
    Location
    Rennes, France
    Posts
    3
    Vote Rating
    0
    Kelenn is on a distinguished road

      0  

    Default


    Thanks, I corrected my code :

    Code:
    Ext.define('HomePage', {
        extend: 'Ext.Container',
        
        requires: ['Ext.util.DelayedTask'],
    
        config: {
            id: 'home-page',
            scrollable: {
                direction: 'vertical',
                directionLock: true
            },
            items: []
        },
        
        initialize: function() {
            this.callParent();
            var   containerOne = this,
                  containerBis = Ext.get('home-page'),
    
                  task = new Ext.util.DelayedTask(function(active) {
                      console.log("test");
                      containerOne.fireEvent("TaskEnded");
                  }, containerOne),
    
                  refreshAlarms = function(active) {
                      if (active) {
                          task.delay(1000);
                          containerOne.on('TaskEnded', task);
                      } else if (!active) {
                          if (containerOne.hasListener('TaskEnded')){
                              containerOne.removeListener('TaskEnded');
                          }
                          task.cancel();
                      }
                  };
    
            this.on('show', function() {            
                  refreshAlarms(true);
            });
            this.on('hide', function(){
                  refreshAlarms(false);
            });
        }
    });
    I still have the same error in Chrome.

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi