Skip to content

Commit

Permalink
add ability to pass fetch_options for a lazy fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiago Archila committed Apr 26, 2015
1 parent 5ada76a commit f0681a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion shared/base/view.js
Expand Up @@ -226,6 +226,7 @@ module.exports = BaseView = Backbone.View.extend({
*/
fetchLazy: function() {
var params = {},
fetchOptions,
fetchSpec;

if (this.options.fetch_params) {
Expand All @@ -238,6 +239,14 @@ module.exports = BaseView = Backbone.View.extend({
params[this.options.param_name] = this.options.param_value;
}

if (this.options.fetch_options) {
if (!_.isObject(this.options.fetch_options)) {
throw new Error('fetch_options must be an object for lazy loaded views')
}

fetchOptions = this.options.fetch_options;
}

if (this.options.model_id != null) {
params.id = this.options.model_id;
}
Expand All @@ -261,7 +270,7 @@ module.exports = BaseView = Backbone.View.extend({
this.setLoading(true);

this._preRender();
this.app.fetch(fetchSpec, this._fetchLazyCallback.bind(this));
this.app.fetch(fetchSpec, fetchOptions, this._fetchLazyCallback.bind(this));
},

_fetchLazyCallback: function(err, results) {
Expand Down
2 changes: 1 addition & 1 deletion shared/fetcher.js
Expand Up @@ -163,7 +163,7 @@ Fetcher.prototype.isMissingKeys = function(modelData, keys) {
};

Fetcher.prototype.fetchFromApi = function(spec, options, callback) {
var model = this.getModelOrCollectionForSpec(spec),
var model = this.getModelOrCollectionForSpec(spec, null, options),
fetcher = this;

model.fetch({
Expand Down

0 comments on commit f0681a8

Please sign in to comment.