How to set the config value in an updater function

#1

Is there a way to set a config value in its own updater function?

Example: (silly and contrived)

foo: { value: 'bar', update: function (newValue, oldValue) { combinedValue = 'baz' + oldValue + newValue; // make value of 'foo' == combinedValue } }

0 Likes

#2

I figured it out: use transform instead of update

1 Like

#3

Yep! You figured it out. transform is used to change the value of an individual config (make sure to return the value at the end of the function), and update uses the already-transformed value of the config to do things like update other config values based on this one, interact with DOM elements if the component is rendered, or trigger methods to occur whenever the parameter is changed.

So you’d want something like

foo: {
      value: 'bar',
      transform: function (newValue, oldValue) {
            combinedValue = 'baz' + oldValue + newValue;
            return combinedValue;
      }
}
0 Likes