JavaScript Upgrade Strategy #7: Code Consolidation

Continuing on our refactor process, we enter the code consolidation phase. This includes the following processes:

 

Remove duplicate functions

One of the features of Transformer! is to identify duplicate functions when performing the conversion process but you can always just hunt these down manually, if necessary.  There are actually two types of duplicates that you need to identify:

 

Duplicate Function Names

Are functions that have the same name but have totally different purposes. This usually happens when you have functions that exist in different entities. If you do run into this situation, there are several possible remedies:

1. You can rename the functions to better match their functionality.

2. You can consolidate functions should they be similar, but not exact, in functionality.

 

Duplicate Functions

These are functions which contain exactly the same functionality, like a FormatPhoneNumber function.  We only need one copy of this function so save one and remove the others.

 

Add to shared JavaScript Libraries

As we discussed in Strategy #5, we need to create shared JavaScript libraries by following this process:

1. Remove duplicate functions, as described above.

2. Create JavaScript libraries as described in Strategy #5.

3. Move functions into the libraries so that you end up with:

  • Entity-specific functions
  • General or utility functions
  • Ribbon functions
  • etc.

 

Again, the idea is to end up with a small a code-base as is possible, by eliminating the duplicates that may be found throughout your existing JavaScript

Leave a Reply 0 comments