close

Filter

loading table of contents...

CoreMedia Content Cloud v11 Upgrade Guide / Version 2110

Table Of Contents
7.3.1.6.1.2 "Bindable" Configs in Ext 6

Things became more complicated with the new class and Config system introduced with Ext 4 (CoreMedia upgraded directly to Ext 6, later to 7). Configs now can be declared for an Ext class and then trigger some magic: For every Config property foo, Ext generates methods getFoo() and setFoo(value). Note that these are not accessors, but "normal" methods, as Ext 4 came out when browser support for accessors was not yet mainstream. They never managed to update their Config system to "real" accessors.

To make things "easier" (?) for the developer, things get even more complicated: the generated setFoo(value) method looks for two optional "hook" methods that allow the following:

  • Transform the value before it is stored: updateFoo(value) { return transform(value) }

  • Trigger side-effects after the value has been set: applyFoo(value, oldValue)

Neglecting this additional "convenience", this is how you could define a Config text, prevent anything that is not a string from being set into that Config (at least not when everybody uses the setText(value) method), and update the DOM of your component when the text is changed afterwards:

 Ext.define("acme.Label", {
  extend: "Ext.Component",
  xtype: "acme.label",
  config: {
    text: ""
  },
  setText(value) {
    this.value = typeof value === "string" ? value : value ? String(value) : "";
    // if rendered, update my DOM node with 'value'
  }
};

var label = Ext.create({ xtype: "acme.label", text: "Hi!"});
label.setText(null);
console.log(button.getText()); // logs the empty string (""), not "null"
          

Example 7.6.  Bindable configs


Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.