Update MooTools from 1.2.5 to 1.3: API breaks with (inbuilt) compatibility layer

Update 2010-10-20: The MooTools team decided that both API changes are not API breaks, but fixes. In detail, both functionalities I’ve used in 1.2.5 are undocumented and officially unsupported features (see Christoph Pojer’s comment and my bug report). The migration guide “Update from 1.2 to 1.3” now refers to the changes in the Request objects.

MooTools 1.3 was released some days ago. The developer team announced the new major version to be fully backwards compatible to the former version 1.2 to enable easy upgrading (MooTools Core 1.3 Stable and MooTools More 1.3RC):

In addition, MooTools Core 1.3 is fully backwards compatible with all documented functionality of MooTools Core 1.2, […].

The backward compatibility is realized by an optional inbuilt compatibility layer that maps the old API to the new one. In detail, when downloading MooTools 1.3 you can choose whether or not to include the compatibility layer in your MooTools build. When I tried to update the MooTools library in my project to 1.3, I found two annoying incompatibilities that are not mentioned in migration guide (Update from 1.2 to 1.3):

  1. Using an (standard) object that does not extend MooTools base class Class as interface throws a JavaScript error “item is not a constructor”.
  2. Passing the URL as (string) to the methods get(), post(), put(), … of the Request objects (Request, Request.HTML, Request.JSON) is no longer supported and results in sending a request to the browser’s current location (document.location.pathname).

The following code demonstrates the first problem:

var MyInterface = {
	sayHello: function() { alert("hello"); }
}
var MyClass = new Class({
	Implements: MyInterface
});
var myObject = new MyClass();
myObject.sayHello(); // works only in MooTools 1.2, throws error "item is not a constructor" in MooTools 1.3

To fix this code for MooTools 1.3, you have to define the interface as follows:

var MyInterface = new Class({
	sayHello: function() { alert("hello"); }
});

The following code demonstrates the second problem:

new Request({onSuccess: function(response) {
	alert(response);
}}).get("data.txt"); // loads data.txt in MooTools 1.2 and the browser's current location in MooTools 1.3

To fix this code for MooTools 1.3, you could pass the url as option to the Request object:

new Request({onSuccess: function(response) {
	alert(response);
}, url: "data.txt"}).get();

You can download the source code of both examples here.

Comments

  1. Christoph Pojer

    Hey,

    thank you for pointing out these issues. Disallowing to mix-in a plain object is definitely a bug fix, however the issue with Request is clearly a bug. Would you mind opening a ticket on our bug tracker? https://mootools.lighthouseapp.com/projects/2706-mootools/overview

  2. Jan Jonas

Leave a comment

Your email address will not be published. Required fields are marked *

*