Union types available in typescript as of 1.4. Some semantically identical overloaded function definitions have been tidied up into single definitions.
The following syntax is supported in Backbone, but is currently not compileable in Typescript:
var data = [
{ id: 1, bar: 'foo' },
{ id: 2, bar: 'baz' }
];
var myCollection = new Backbone.Collection(data);
As of now, the constructor expects an array of models. I've added the Object[] parameter type, in addition to the TModel[] type to support this syntax.
http://backbonejs.org/#Utility-Backbone-$
Also removed `setDomLibrary`
Backbone change log 0.9.9 — Dec. 13, 2012:
To set what library Backbone uses for DOM manipulation and Ajax calls,
use `Backbone.$ = ...` instead of `setDomLibrary`.
Also updated version number. Added appropriate types to all the functions where I could find them, otherwise typed them with any. This now will compile for typescript compilers that have the noImplictAny flag set.
// Bind an event to a `callback` function. Passing `"all"` will bind
// the callback to all events fired.
on: function(name, callback, context) {
if (!eventsApi(this, 'on', name, [callback, context]) || !callback) return this;
========
// Implement fancy features of the Events API such as multiple event
// names `"change blur"` and jQuery-style event maps `{change: action}`
// in terms of the existing API.
var eventsApi = function(obj, action, name, rest) {
if (!name) return true;
// Handle event maps.
if (typeof name === 'object') {
for (var key in name) {
obj[action].apply(obj, [key, name[key]].concat(rest));
}
return false;
}
Signed-off-by: areel <aidanreel@gmail.com>
As of typescript 0.9.1, fields are set after calling the super
constructor, so if events, defaults, or routes are set to object
literals, they will not be seen by backbone, and will not be bound.
The cleanest way to fix this is to define them as methods which return
an object hash, as the methods are already on the prototype chain when
backbone looks for events/defaults/routes, and backbone supports either
objects or functions that when called return objects.