Options
All
  • Public
  • Public/Protected
  • All
Menu

DepResolver is a multi-parent dependency resolution algorithm, made to resolve dependencies optimally whilst detecting unresolvable or circular dependencies.

Hierarchy

  • DepResolver

Index

Properties

Methods

Properties

Protected ingestNodes

ingestNodes: DepNode[] = []

Methods

addInstance

  • addInstance(instanceName: string, instanceParents?: string[] | string, instanceOptParents?: string[] | string, instance?: any): void
  • Add an instance to the resolution tree.

    example
    import { DepResolver } from 'treeresolver'
    const tree = new DepResolver()
    
    // add nodes to use when building the dependency tree with individual DepResolver.addInstance() calls
    tree.addInstance('node 1')
    tree.addInstance('node 2', ['node 1'])
    tree.addInstance('node 3', ['node 1', 'node 2'])
    
    // ...

    Parameters

    • instanceName: string

      The name of this instance.

    • Optional instanceParents: string[] | string

      (optional) The name of the parents of this instance. Coerced into an array if a single string is provided.

    • Optional instanceOptParents: string[] | string

      (optional) The name of any optional parents of this instance. Coerced into an array if a single string is provided.

    • Optional instance: any

      An object or anything really to tie to this instance.

    Returns void

build

  • Build the dependency tree.

    example
    import { DepResolver } from 'treeresolver'
    const tree = new DepResolver()
    
    tree.addInstance('node 1')
    tree.addInstance('node 2', ['node 1'])
    tree.addInstance('node 3', ['node 1', 'node 2'])
    
    (async () => {
      // build the tree, and then
      const res = await tree.build()
      console.dir(res)
    })()

    Returns Promise<DepResolverResult>

clear

  • clear(): void
  • Clears out all added instances, to allow the resolver to start fresh.

    example
    import { DepResolver } from 'treeresolver'
    const tree = new DepResolver()
    
    tree.addInstance('node 1')
    tree.addInstance('node 2', ['node 1'])
    
    // ...
    
    // actually, we changed our mind, clear out all the nodes to process.
    tree.clear()

    Returns void

Legend

  • Property
  • Method
  • Protected property

Generated using TypeDoc