Skip to content

Commit

Permalink
added updateRegions and updateRegion to the router; they also now ret…
Browse files Browse the repository at this point in the history
…urn a promise. bump to 0.6
  • Loading branch information
jtward committed Feb 27, 2013
1 parent d9368ce commit 5cf9c6d
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 100 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ When authentication fails, the router looks for the `authenticateRedirect` prope
The ActivityRouter's `resolveAuthentication` method re-checks authentication and redirects the user to the protected page if they are authenticated. If authentication fails, then no action is taken.

## Change Log
### 0.6.0
- Added `updateRegions` and `updateRegion` to the `ActivityRouter` prototype. The corresponding methods on `ActivityRouteHandler` now defer to the router.
- `updateRegions` and `updateRegion` now return a promise which is resolved when the region(s) have been rendered.

### 0.5.3
- Fixed a bug where calling `ActivityRouteHandler.updateRegion` for a second time for a region before the previous views had been rendered would cause both sets of views to be shown.

Expand All @@ -174,4 +178,4 @@ The ActivityRouter's `resolveAuthentication` method re-checks authentication and

### 0.4.0
- Built-in support for protected handlers and activities and authentication was added
- Support for URL fragments was added; they can now be used for the default route and for authentication redirects
- Support for URL fragments was added; they can now be used for the default route and for authentication redirects
210 changes: 111 additions & 99 deletions backbone.activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
var Backbone = root.Backbone;
var _ = root._ || root.underscore || root.lodash;
var $ = Backbone.$ || root.$ || root.jQuery || root.Zepto || root.ender;
var when = Backbone.Layout.prototype.options.when;

var VERSION = '0.5.3';
var VERSION = '0.6.0';

Backbone.ActivityRouter = Backbone.Router.extend({

Expand Down Expand Up @@ -279,110 +280,18 @@
return result;
},

VERSION: VERSION

});

// Activity constructor
Backbone.Activity = function(options) {
this._configure(options || {});
this.initialize.apply(this, arguments);
};

// mix events into the prototype
_.extend(Backbone.Activity.prototype, Backbone.Events, {

// Performs the initial configuration of an Activity with a set of options.
// Keys with special meaning *(routes)* are attached directly to the activity.
_configure: function(options) {
if (options.routes) {
this.routes = options.routes;
}
if (options.handlers) {
this.handlers = options.handlers;
}
if (options.authenticate) {
this.authenticate = options.authenticate;
}
if (options.authenticateRedirect) {
this.authenticateRedirect = options.authenticateRedirect;
}
if (options.isProtected !== null && options.isProtected !== undefined) {
this.isProtected = options.isProtected;
}
},

// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function() {},

// The router uses this value to determine whether to call an activity's onCreate
// callback
_initialized: false,

// callback stubs
onCreate: function() {},
onStart: function() {},
onStop: function() {},

VERSION: VERSION

});

// use backbone's extend (referencing via View here, but they're all the same)
Backbone.Activity.extend = Backbone.View.extend;

// Activity constructor
Backbone.ActivityRouteHandler = function(options) {
this._configure(options || {});
this.initialize.apply(this, arguments);
};

// mix events into the prototype
_.extend(Backbone.ActivityRouteHandler.prototype, Backbone.Events, {

// regions is a map from region names to region objects.
// Setup is handled by the ActivityRouter constructor.
// This object will be the same for all handlers associated with the same router.
regions: {},

// layouts is an object of layout names to layout functions
layouts: {},

// Performs the initial configuration of an ActivityRouteHandler with a set of options.
// Keys with special meaning *(layouts)* are attached directly to the activity.
_configure: function(options) {
if (options.layouts) {
this.layouts = options.layouts;
}
if (options.authenticate) {
this.authenticate = options.authenticate;
}
if (options.authenticateRedirect) {
this.authenticateRedirect = options.authenticateRedirect;
}
if (options.isProtected !== null && options.isProtected !== undefined) {
this.isProtected = options.isProtected;
}
},

// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function() {},

// The router uses this value to determine whether to call an activity's onCreate
// callback
_initialized: false,

// updateRegions takes an object of regions by name
// For each region given, the corresponding views are inserted. See updateRegion
// below for details.
updateRegions: function(regions) {

var promises = [];
_.each(regions, function(views, regionName) {
this.updateRegion(regionName, views);
promises.push(this.updateRegion(regionName, views));
}, this);

return when.apply(null, promises);

},

// updateRegion takes a region and either a view or an object with a template
Expand Down Expand Up @@ -474,7 +383,110 @@
});

// render the region and all of its views
region.render();
return region.render();
},

VERSION: VERSION

});

// Activity constructor
Backbone.Activity = function(options) {
this._configure(options || {});
this.initialize.apply(this, arguments);
};

// mix events into the prototype
_.extend(Backbone.Activity.prototype, Backbone.Events, {

// Performs the initial configuration of an Activity with a set of options.
// Keys with special meaning *(routes)* are attached directly to the activity.
_configure: function(options) {
if (options.routes) {
this.routes = options.routes;
}
if (options.handlers) {
this.handlers = options.handlers;
}
if (options.authenticate) {
this.authenticate = options.authenticate;
}
if (options.authenticateRedirect) {
this.authenticateRedirect = options.authenticateRedirect;
}
if (options.isProtected !== null && options.isProtected !== undefined) {
this.isProtected = options.isProtected;
}
},

// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function() {},

// The router uses this value to determine whether to call an activity's onCreate
// callback
_initialized: false,

// callback stubs
onCreate: function() {},
onStart: function() {},
onStop: function() {},

VERSION: VERSION

});

// use backbone's extend (referencing via View here, but they're all the same)
Backbone.Activity.extend = Backbone.View.extend;

// Activity constructor
Backbone.ActivityRouteHandler = function(options) {
this._configure(options || {});
this.initialize.apply(this, arguments);
};

// mix events into the prototype
_.extend(Backbone.ActivityRouteHandler.prototype, Backbone.Events, {

// regions is a map from region names to region objects.
// Setup is handled by the ActivityRouter constructor.
// This object will be the same for all handlers associated with the same router.
regions: {},

// layouts is an object of layout names to layout functions
layouts: {},

// Performs the initial configuration of an ActivityRouteHandler with a set of options.
// Keys with special meaning *(layouts)* are attached directly to the activity.
_configure: function(options) {
if (options.layouts) {
this.layouts = options.layouts;
}
if (options.authenticate) {
this.authenticate = options.authenticate;
}
if (options.authenticateRedirect) {
this.authenticateRedirect = options.authenticateRedirect;
}
if (options.isProtected !== null && options.isProtected !== undefined) {
this.isProtected = options.isProtected;
}
},

// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function() {},

// The router uses this value to determine whether to call an activity's onCreate
// callback
_initialized: false,

updateRegions: function(regions) {
return this.router.updateRegions(regions);
},

updateRegion: function(region, views) {
return this.router.updateRegion(region, views);
},

// callback stubs
Expand All @@ -491,4 +503,4 @@

// The module returns Backbone.
return Backbone;
}(this));
}(this));

0 comments on commit 5cf9c6d

Please sign in to comment.