angular/packages/core/src/application_config.ts
Alan Agius 4e9531f777 feat(core): add mergeApplicationConfig method (#49253)
This commits add a utility method to merge multiple `ApplicationConfiguration` into one from left to right.  This is useful for server rendering were an application might have several configurations.

Usage Example:
```ts
const config = mergeApplicationConfig(appConfig, appServerConfig);
```

PR Close #49253
2023-03-01 11:20:31 -08:00

36 lines
1 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {EnvironmentProviders, Provider} from './di';
/**
* Set of config options available during the application bootstrap operation.
*
* @publicApi
*/
export interface ApplicationConfig {
/**
* List of providers that should be available to the root component and all its children.
*/
providers: Array<Provider|EnvironmentProviders>;
}
/**
* Merge multiple application configurations from left to right.
*
* @param configs Two or more configurations to be merged.
* @returns A merged [ApplicationConfig](api/core/ApplicationConfig).
*
* @publicApi
*/
export function mergeApplicationConfig(...configs: ApplicationConfig[]): ApplicationConfig {
return configs.reduce((prev, curr) => {
return Object.assign(prev, curr, {providers: [...prev.providers, ...curr.providers]});
}, {providers: []});
}