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.
having the "sort" version of the comparator return a number, while technically correct according to the Backbone documentation, does not actually work when the "sortBy" version of the comparator is used.
* Model.urlRoot should be any, as it may be a string or a function.
* Added internal methods to Router.
* Improved definition of History:
- Extends Events
- Remove pushState method, it doesn't exist in the source
- Added internal methods to definition.
The Backbone.Router class did not previously extend Events in the
definition file. This caused the TypeScript compiler to raise an
error when calling one of the Events methods (such as on()) on an
instance of a router.
This change allows instances of classes derived from Backbone.Router
to call methods on the Events class that are inherited by the router.
This enables each definition to have a readme if necessary.
Also a .json metadata file to help with package managers.
And last, to have different versions of the definitions.