Aspect Configuration

Aspects accepts configuration upon compositon to an Harmony platform. They can also be defined with default configuraiton using the static defaultConfig property on the Aspect class.

Accept a second config arugment in your provider function to use the Aspect config:

import { PeopleConfig } from 'people-config.js';

export class PeopleBrowser {

  // sets the aspect default config
  static defaultConfig: PeopleConfig = {
    provider: 'auth0'
  };

  static async provider(deps, config: PeopleConfig) {
    console.log(config) // echos { provider: 'auth0' } unless configured otherwise by the platform.
    return new PeopleBrowser();
  }
}
CopiedCopy

Create the config type

Create the configuration type is useful as a convention for storing and finding aspect configuration types. Add a file named people-config.ts to your aspect with your type definition:

export type PeopleConfig = {
  /**
   * provider to use.
   */
  provider?: string;
};
CopiedCopy

Configuring Aspects in Harmony platforms

Aspects can be provided with a different configuration upon composition to an Harmony platform. Provide an tuple array instead of the Aspect an provide configuration at the second location:

/**
 * compose the pied piper platform.
 */    
export const PiedPiperPlatform = HarmonyPlatform.from({
  name: 'pied-piper',

  /**
   * platform aspect to compose.
   */
  platform: [SymphonyPlatformAspect],

  aspects: [
    [PeopleAspect, {
      authProvider: 'bit'
    }],
  ],
});

export default PiedPiperPlatform;
CopiedCopy

Configuring the aspect in an Harmony platform overrides the default configuration.