5

I'm experimenting with Angular schematics, and have encountered the function branchAndMerge() in various places. No one explains what it does, however.

Places I have seen it:

A clarification of how it differs from merge/mergeWith, and how to use it correctly would be appreciated.

P.S: Merge is explained at @angular-devkit/schematics as follows:

Merge the input tree with the other Tree.

Btw I assume that merge() is now mergeWith, though I'm not 100% sure on that.

Code example

const rule = 
    // Creates a new rule that is a concatenation of other rules.
    chain([
      // Everyone uses it, but no one explains what it does...
      branchAndMerge(
        chain([
        // Merges the project tree with the virtual tree
        mergeWith(virtualTree)
      ]))
    ]);
MartinJH
  • 2,590
  • 5
  • 36
  • 49

1 Answers1

2

The following video gives the best explanation I've heard of so far:

Branch from current tree, and the tree is a virtual file system based off of your current directory

If one were to look into the code in the repo, one will see this is indeed the case. I would imagine the benefit of doing so, is for performance reasons, wherein it allows one to modify key/values instead of an actual hard disk. In addition, I would imagine it also simplifies process, as it makes the location irrelevant, which can greatly complicate process of schematics.

Charlie-Greenman
  • 1,469
  • 1
  • 16
  • 36