WJSoftware/wj-config

Re-design IEnvironment

Closed this issue · 1 comments

Purpose

Provide new properties that allow access to all environment definitions as well as the currently selected environment definition.

Design

  1. Replace the value property with a current property of type IEnvironmentDefinition.
  2. Replace the names property with a all property of type IEnvironmentDefinition[].
  3. Add an hasTraits() function to test if the current environment contains the specified traits.
  4. Ammend the specifier for any additional properties accordingly.
    /**
     * Defines the capabilities required from environment objects.
     */
    export interface IEnvironment {
        /**
         * The current environment (represented by an environment definition).
         */
        readonly current: IEnvironmentDefinition;

        /**
         * The list of known environments (represented by a list of environment definitions).
         */
        readonly all: IEnvironmentDefinition[];

        /**
         * Tests the current environment definition for the presence of the specified traits.  It will return true 
         * only if all specified traits are present; othewise it will return false.
         * @param traits The environment traits expected to be found in the current environment definition.
         */
        hasTraits(traits: Traits): boolean;
        [x: string | 'current' | 'all' | 'hasTraits']: EnvironmentTest | IEnvironmentDefinition | IEnvironmentDefinition[] | ((Traits) => boolean)
    }

Environment Class

  1. Add the current property to the class to comply with the changes done in IEnvironment.
  2. The list of environments received in the constructor needs to be checked so names are unique.
  3. The list of environments can be a list of strings, a mixture of strings and IEnvironmentDefinition objects, or pure IEnvironmentDefinition objects.
  4. Any environment received as a string will be converted to an IEnvironmentDefinition object with no traits.
  5. By default, no-trait environments will define a numeric traits value of zero (0).
  6. The environments must all adhere to the same trait data type: If one environment defines traits as a number, then all other environments must define traits as numbers, and ditto with the string data type.

Deployed in RC0.