From f5fff5097cc835d5e1d5493572d5dc67d273cf04 Mon Sep 17 00:00:00 2001 From: Camille Reynders Date: Thu, 31 Mar 2016 14:12:14 +0200 Subject: [PATCH] Make model parameter optional for Backbone.sync --- backbone.js | 4 +++- test/sync.js | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/backbone.js b/backbone.js index 2ca5cd53b..ff93bc40d 100644 --- a/backbone.js +++ b/backbone.js @@ -1441,7 +1441,9 @@ // Make the request, allowing the user to override any Ajax options. var xhr = options.xhr = Backbone.ajax(_.extend(params, options)); - model.trigger('request', model, xhr, options); + if (model){ + model.trigger('request', model, xhr, options); + } return xhr; }; diff --git a/test/sync.js b/test/sync.js index 8813f1584..931d56d4d 100644 --- a/test/sync.js +++ b/test/sync.js @@ -236,4 +236,10 @@ this.ajaxSettings.error({}, 'textStatus', 'errorThrown'); }); + QUnit.test('`model` is optional', function(assert) { + assert.expect(0); + Backbone.sync('read', null, { + url: '/library' + }); + }); })();