Balaji P
Balaji P

Reputation: 31

Migrating jQuery from 1.12.3 to latest 3.5.1

I am in the process of upgrading jQuery from 1.12.3 to 3.5.1(latest version). My application is large and we have jQuery version 1.12.3. While upgrading with help of jQuery migration script, have faced few technical challenges:

  1. Can't upgrade directly from version 1.x.x to 3.x.x (obviously we can't do that clearly they mentioned in jQuery guide. Because most of the api are deprecated in 1.x.x versions).
  2. For testing purposes first, I tried a 3.5.1 jQuery with 3.3.0 migration script. Its generating more blocker issues since my application is using by most of the clients with jQuery version(1.12.3). So I have planned to move step by step migration first to 2.2.4 jQuery with 1.4.1 migration. In my application we are using a lot of die() and live() events for a single module,hence I have planned to make our own migration script for die() and live() events. Here is the code for live(), which converts to on().
jQuery.fn.live = function( types, data, fn ) {
    
    try{
      if(typeof(this.selector) == "undefined" && typeof(this[0].id) != "undefined"){
        this.selector = String("#" + this[0].id);
      }
    }catch(e){
        }   
    if(typeof(this.context) == "undefined"){
        this.context = jQuery(this).parent();
    }
    else{
        this.context = "body";
    }
    jQuery( this.context ).on( types, this.selector, data, fn );
    return this;
};

It's working well. when using the same technique for Die() it is not working. because for example

$(".selector").die().live("click",function(){}).

We can't get events and selector for the die function. So I dropped this option. Is there's any other way to upgrade jQuery with minimal code changes?

or

If I change the on() and off() method manually, How can I ensure the events are working properly instead of manual testing. Since manual code replacement and testing will impact out web app development road map timeline.

Upvotes: 3

Views: 3323

Answers (0)

Related Questions