@combeenation/custom-code-sdk
    Preparing search index...

    Function createSyncCmpValuesStore

    • Creates a store holding component values which can be accessed synchronously.

      This is meant as an alternative to the async value access via await cmp.getValue() for situations where the async access is especially cumbersome.

      E.g.:

      const amount = await Amount.getValue();
      // vs.
      const amount = cmpValues.Amount;

      !!! Note !!!

      This shall not be used as the default way of accessing component values.
      Using this extensively can have negative impact on the performance of your configurator.

      Avoid using this with too many components or components that hold very large values which change frequently.

      Type Parameters

      • TCmps extends { [id: string]: ValueComponent<string, unknown, unknown> }

      Parameters

      Returns Promise<Readonly<SyncCmpValuesStore<TCmps>>>

      An object holding the current value of each of the given cmps.
      The keys of the properties in the returned object are the same as in the given cmps.

      // Create the store once and export for later use:
      import { Amount, ItemPrice } from './typings/cfgr-defs.generated';
      export const cmpValues = await createSyncCmpValuesStore({ Amount, ItemPrice });

      // Later in the code, access the values synchronously like this:
      const amount = cmpValues.Amount;
      const itemPrice = cmpValues.ItemPrice;
      // or:
      const { Amount: amount, ItemPrice: itemPrice } = cmpValues;

      !!! Important !!!

      Once the values of the returned store have been extracted, they will not update anymore.
      -> Only extract the values in sync contexts.

      E.g.:

      import { cmpValues } from './path/to/store';

      const amount = cmpValues.Amount; // Current value of Amount is 10

      button.onClick(() => {
      // The value of Amount changed to 20 in the meantime
      console.log(amount); // 🔥 Stale value 10
      console.log(cmpValues.Amount); // ✅ Latest value 20
      });