true-di
githubnpm
  • Introduction
  • Core
    • diContainer
    • multiple
    • isReady
    • prepareAll
    • releaseAll
    • factoriesFrom
  • Utils
    • assignProps
    • shallowMerge
  • Recipes
    • Accessing Items
    • Releasing Items
    • Creating All Items
    • Cyclic Dependencies
    • Injection Context
    • Creating Factories before Container
Powered by GitBook
On this page
  • Import
  • Declaration
  • Arguments
  • Returns
  • Types
  • Example

Was this helpful?

  1. Utils

shallowMerge

creates new object and copies to the one property descriptors of all source objects. In case of name-conflict last source wins.

PreviousassignPropsNextAccessing Items

Last updated 4 years ago

Was this helpful?

Import

import { shallowMerge } from 'true-di/utils';
const { shallowMerge } = require('true-di/utils');

Declaration

function shallowMerge(...sourceObject: object[]): object

Actually shallowMerge is well-typed up to 15 source objects. See .

Arguments

  • sourceObjects: object[] - objects to be merged in new objects.

Returns

  • new object

Types

export type Merge<T1 extends object, T2 extends object> =
  Omit<T1, keyof T2> & T2; // Overriding Join

Example

import diContainer, { factoriesFrom } from 'true-di';

type IContainer1 = {
  service11: IService11,
  service12: IService12,
}

type IContainer2 = {
  service11: IService11,
  service12: IService12,
}

const container1 = diContainer<IContainer1>(Object.create(null, {
  service11: { enumerable: false, value: () => createService11() },
  service12: { enumerable: false, value: () => createService12() },
}));

const container2 = diContainer<IContainer1>(Object.create(null, {
  service21: { enumerable: false, value: () => createService21() },
  service22: { enumerable: false, value: () => createService22() },
}));

export default diContainer<IContainer1 & IContainer2>(shallowMerge(
  factoriesFrom(container1),
  factoriesFrom(container2),
));
code source