Results 1 to 2 of 2

Thread: Difference between applyX, updateX, setX, and doSetX?

  1. #1
    Ext JS Premium Member
    Join Date
    Apr 2011
    Posts
    25

    Default Difference between applyX, updateX, setX, and doSetX?

    where X is some variable in a class's config

    Can someone give me a rundown of what the difference between them is? As far as I can tell from docs, applyX happens before setX when calling setX, but other than that, I'm not sure.

    Thanks

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    I'm assuming you are talking about the config object system. Little disclaimer, the framework doesn't use this internally but you can use it in your application code.

    If you have this in your Ext.define code:

    config : {
    foo : 'bar'
    }

    and of course called initConfig in the constructor your class will now have a getFoo and setFoo method. The getFoo will return the foo property but the setFoo is more advanced than that.

    When setFoo is executed, it will check if applyFoo method exists. If so then it will execute it where it expects something returned. setFoo will then set the value onto the foo property. It will then check if updateFoo exists and if so then will execute it and this ends what setFoo will do. If that wasn't understandable then maybe this code:

    Code:
    setFoo : function(value) {
        var oldValue = this.foo;
    
        if (this.applyFoo) {
            value = this.applyFoo(value, oldValue);
        }
    
        this.foo = value;
    
        if (this.updateFoo) {
            this.updateFoo(value, oldValue);
        }
    }
    applyFoo is often used to transform the value being passed and updateFoo is to take action on the new value.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •