close

Filter

loading table of contents...

CoreMedia Content Cloud v11 Upgrade Guide / Version 2110

Table Of Contents
7.3.1.6.3.4 Merging Config Objects

When receiving a Config object, the typical things a constructor does is:

  • Apply the received config on its own Config defaults

  • Hand through the resulting Config to its super constructor

In TypeScript code, this could be done like this:

 constructor(config: Config<MyClass>) {
  super(Object.assign(Config<MyClass>({
    id: "4711",
    configOption1: "bar",
    configOption2: [42, 24]
  }), config));
} 

Example 7.19.  Typical work of constructor done in TypeScript


However, there is a special utility class named ConfigUtils (formerly in ActionScript: Exml) that helps implementing a specific merge logic. For array-valued properties, it should be possible to instead of replacing the whole array, append or prepend to the existing value. The concrete use cases where this often makes sense are Ext component's plugins and items properties. So at least if your class has any array-valued properties, in your constructor, you should use the following:

 import ConfigUtils from "@jangaroo/runtime/ConfigUtils";
...
    constructor(config: Config<MyClass>) {
      super(ConfigUtils.apply(Config<MyClass>({
        id: "4711",
        configOption1: "bar",
        configOption2: [42, 24]
      }), config));
    } 

Example 7.20.  Using ConfigUtils utility class


Any client using such a component can then use

import ConfigUtils from "@jangaroo/runtime/ConfigUtils";
...
      Config(MyClass, {
        id: "4711",
        configOption1: "bar",
        ...ConfigUtils.append({
          configOption2: [12]
        }
      }), config));
    }

Example 7.21.  Component with utility class in client


The resulting value of configOption2 after merging via ConfigUtils.apply() will be [42, 24, 12]. There is an analogous utility method ConfigUtils.prepend(). Both return an object, handing through the given property, complementing it by an internal marker property that specifies where to insert the value into the previous value. To "lift" these properties into surrounding object code, the spread operator ... is used.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

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