Migration: Patching

This article describes the differences between 3.x and 4.0. It's primarily focused on the JavaScript capabilities. If you are interested only in Client API changes, please visit this article.

JavaScript Interpreter

The Jint, a JavaScript interpreter used to perform JS operations (like patching), was updated from version 2 to version 3, which supports wider range of capabilities (e.g. ECMAScript 5.1 with some 6.0 features like arrow functions).

Removed Libraries

Lodash

Due to performance reasons (parsing time), Lodash is no longer included as a part of every patch.

RavenDB JavaScript extensions

All of the non-standard methods like RemoveWhere, Map (full list available here) were also removed due to additional parsing time needed to perform JS operations. Most of them can be easily substituted with ECMAScript 5.1 or 6 capabilities built-in in the Jint engine (check examples).

Custom Functions

The ability to write your own custom functions and share them between patches has been dropped. Functions can be inlined inside a patching script and will work.

Example I

3.x
var item = _.find(myArray, function(item) {
    return item.Id == args.Id;
});
4.0
var item = myArray.filter(a => a.Id == args.Id)[0];

Example II

3.x
_.forEach(myArray, function(item) {
    item.Name = args.Name;
    item.City = args.City;
    item.Mascot = args.Mascot;
});
4.0
for(var i = 0; i < myArray.length; i++)
{
    var item = myArray[i];
    item.Name = args.Name;
    item.City = args.City;
    item.Mascot = args.Mascot; 
}

Example III

3.x
this.MyArray.RemoveWhere(function(item) {
    return item.Id == args.Id;
});
4.0
this.MyArray = this.MyArray.filter(i => i.Id != args.Id);

Example IV

3.x
var myArray = this.AllItems.Where(function(item) {
    return item.Id == args.Id;
});
4.0
var myArray = this.MyArray.filter(i => i.Id == args.Id);

Do you need any help with Migration?