mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Update vendors.
Former-commit-id: 4ffc3f5b267f8fdf1ac074f9f9ab44b0a7c4c3dd
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
var closureId = 'c92fd8f7f2b2096eb910c99d10ede0ec25d3c3cc';
|
var closureId = 'c92fd8f7f2b2096eb910c99d10ede0ec25d3c3cc';
|
||||||
|
|
||||||
/** The Git object ID of `uglifyjs.tar.gz` */
|
/** The Git object ID of `uglifyjs.tar.gz` */
|
||||||
var uglifyId = 'db14216975ad703f8b903a9c4bbcfe9ecb824c61';
|
var uglifyId = '7948672b0f85eeaba258c7298b2422fc5ea594b2';
|
||||||
|
|
||||||
/** The path of the directory that is the base of the repository */
|
/** The path of the directory that is the base of the repository */
|
||||||
var basePath = fs.realpathSync(path.join(__dirname, '..'));
|
var basePath = fs.realpathSync(path.join(__dirname, '..'));
|
||||||
|
|||||||
102
vendor/backbone/backbone.js
vendored
102
vendor/backbone/backbone.js
vendored
@@ -193,15 +193,12 @@
|
|||||||
stopListening: function(obj, name, callback) {
|
stopListening: function(obj, name, callback) {
|
||||||
var listeners = this._listeners;
|
var listeners = this._listeners;
|
||||||
if (!listeners) return this;
|
if (!listeners) return this;
|
||||||
if (obj) {
|
var deleteListener = !name && !callback;
|
||||||
obj.off(name, typeof name === 'object' ? this : callback, this);
|
if (typeof name === 'object') callback = this;
|
||||||
if (!name && !callback) delete listeners[obj._listenerId];
|
if (obj) (listeners = {})[obj._listenerId] = obj;
|
||||||
} else {
|
for (var id in listeners) {
|
||||||
if (typeof name === 'object') callback = this;
|
listeners[id].off(name, callback, this);
|
||||||
for (var id in listeners) {
|
if (deleteListener) delete this._listeners[id];
|
||||||
listeners[id].off(name, callback, this);
|
|
||||||
}
|
|
||||||
this._listeners = {};
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -216,7 +213,8 @@
|
|||||||
var listeners = this._listeners || (this._listeners = {});
|
var listeners = this._listeners || (this._listeners = {});
|
||||||
var id = obj._listenerId || (obj._listenerId = _.uniqueId('l'));
|
var id = obj._listenerId || (obj._listenerId = _.uniqueId('l'));
|
||||||
listeners[id] = obj;
|
listeners[id] = obj;
|
||||||
obj[implementation](name, typeof name === 'object' ? this : callback, this);
|
if (typeof name === 'object') callback = this;
|
||||||
|
obj[implementation](name, callback, this);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -420,11 +418,14 @@
|
|||||||
fetch: function(options) {
|
fetch: function(options) {
|
||||||
options = options ? _.clone(options) : {};
|
options = options ? _.clone(options) : {};
|
||||||
if (options.parse === void 0) options.parse = true;
|
if (options.parse === void 0) options.parse = true;
|
||||||
|
var model = this;
|
||||||
var success = options.success;
|
var success = options.success;
|
||||||
options.success = function(model, resp, options) {
|
options.success = function(resp) {
|
||||||
if (!model.set(model.parse(resp, options), options)) return false;
|
if (!model.set(model.parse(resp, options), options)) return false;
|
||||||
if (success) success(model, resp, options);
|
if (success) success(model, resp, options);
|
||||||
|
model.trigger('sync', model, resp, options);
|
||||||
};
|
};
|
||||||
|
wrapError(this, options);
|
||||||
return this.sync('read', this, options);
|
return this.sync('read', this, options);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -432,7 +433,7 @@
|
|||||||
// If the server returns an attributes hash that differs, the model's
|
// If the server returns an attributes hash that differs, the model's
|
||||||
// state will be `set` again.
|
// state will be `set` again.
|
||||||
save: function(key, val, options) {
|
save: function(key, val, options) {
|
||||||
var attrs, success, method, xhr, attributes = this.attributes;
|
var attrs, method, xhr, attributes = this.attributes;
|
||||||
|
|
||||||
// Handle both `"key", value` and `{key: value}` -style arguments.
|
// Handle both `"key", value` and `{key: value}` -style arguments.
|
||||||
if (key == null || typeof key === 'object') {
|
if (key == null || typeof key === 'object') {
|
||||||
@@ -458,8 +459,9 @@
|
|||||||
// After a successful server-side save, the client is (optionally)
|
// After a successful server-side save, the client is (optionally)
|
||||||
// updated with the server-side state.
|
// updated with the server-side state.
|
||||||
if (options.parse === void 0) options.parse = true;
|
if (options.parse === void 0) options.parse = true;
|
||||||
success = options.success;
|
var model = this;
|
||||||
options.success = function(model, resp, options) {
|
var success = options.success;
|
||||||
|
options.success = function(resp) {
|
||||||
// Ensure attributes are restored during synchronous saves.
|
// Ensure attributes are restored during synchronous saves.
|
||||||
model.attributes = attributes;
|
model.attributes = attributes;
|
||||||
var serverAttrs = model.parse(resp, options);
|
var serverAttrs = model.parse(resp, options);
|
||||||
@@ -468,9 +470,10 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (success) success(model, resp, options);
|
if (success) success(model, resp, options);
|
||||||
|
model.trigger('sync', model, resp, options);
|
||||||
};
|
};
|
||||||
|
wrapError(this, options);
|
||||||
|
|
||||||
// Finish configuring and sending the Ajax request.
|
|
||||||
method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
|
method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
|
||||||
if (method === 'patch') options.attrs = attrs;
|
if (method === 'patch') options.attrs = attrs;
|
||||||
xhr = this.sync(method, this, options);
|
xhr = this.sync(method, this, options);
|
||||||
@@ -493,15 +496,17 @@
|
|||||||
model.trigger('destroy', model, model.collection, options);
|
model.trigger('destroy', model, model.collection, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
options.success = function(model, resp, options) {
|
options.success = function(resp) {
|
||||||
if (options.wait || model.isNew()) destroy();
|
if (options.wait || model.isNew()) destroy();
|
||||||
if (success) success(model, resp, options);
|
if (success) success(model, resp, options);
|
||||||
|
if (!model.isNew()) model.trigger('sync', model, resp, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.isNew()) {
|
if (this.isNew()) {
|
||||||
options.success(this, null, options);
|
options.success();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
wrapError(this, options);
|
||||||
|
|
||||||
var xhr = this.sync('delete', this, options);
|
var xhr = this.sync('delete', this, options);
|
||||||
if (!options.wait) destroy();
|
if (!options.wait) destroy();
|
||||||
@@ -602,10 +607,7 @@
|
|||||||
// Turn bare objects into model references, and prevent invalid models
|
// Turn bare objects into model references, and prevent invalid models
|
||||||
// from being added.
|
// from being added.
|
||||||
for (i = 0, l = models.length; i < l; i++) {
|
for (i = 0, l = models.length; i < l; i++) {
|
||||||
if (!(model = this._prepareModel(attrs = models[i], options))) {
|
if (!(model = this._prepareModel(attrs = models[i], options))) continue;
|
||||||
this.trigger('invalid', this, attrs, options);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a duplicate is found, prevent it from being added and
|
// If a duplicate is found, prevent it from being added and
|
||||||
// optionally merge it into the existing model.
|
// optionally merge it into the existing model.
|
||||||
@@ -712,8 +714,7 @@
|
|||||||
// Get a model from the set by id.
|
// Get a model from the set by id.
|
||||||
get: function(obj) {
|
get: function(obj) {
|
||||||
if (obj == null) return void 0;
|
if (obj == null) return void 0;
|
||||||
this._idAttr || (this._idAttr = this.model.prototype.idAttribute);
|
return this._byId[obj.id || obj.cid || obj];
|
||||||
return this._byId[obj.id || obj.cid || obj[this._idAttr] || obj];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get the model at the given index.
|
// Get the model at the given index.
|
||||||
@@ -721,10 +722,11 @@
|
|||||||
return this.models[index];
|
return this.models[index];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Return models with matching attributes. Useful for simple cases of `filter`.
|
// Return models with matching attributes. Useful for simple cases of
|
||||||
where: function(attrs) {
|
// `filter`.
|
||||||
if (_.isEmpty(attrs)) return [];
|
where: function(attrs, first) {
|
||||||
return this.filter(function(model) {
|
if (_.isEmpty(attrs)) return first ? void 0 : [];
|
||||||
|
return this[first ? 'find' : 'filter'](function(model) {
|
||||||
for (var key in attrs) {
|
for (var key in attrs) {
|
||||||
if (attrs[key] !== model.get(key)) return false;
|
if (attrs[key] !== model.get(key)) return false;
|
||||||
}
|
}
|
||||||
@@ -732,6 +734,12 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Return the first model with matching attributes. Useful for simple cases
|
||||||
|
// of `find`.
|
||||||
|
findWhere: function(attrs) {
|
||||||
|
return this.where(attrs, true);
|
||||||
|
},
|
||||||
|
|
||||||
// Force the collection to re-sort itself. You don't need to call this under
|
// Force the collection to re-sort itself. You don't need to call this under
|
||||||
// normal circumstances, as the set will maintain sort order as each item
|
// normal circumstances, as the set will maintain sort order as each item
|
||||||
// is added.
|
// is added.
|
||||||
@@ -762,7 +770,7 @@
|
|||||||
update: function(models, options) {
|
update: function(models, options) {
|
||||||
options = _.extend({add: true, merge: true, remove: true}, options);
|
options = _.extend({add: true, merge: true, remove: true}, options);
|
||||||
if (options.parse) models = this.parse(models, options);
|
if (options.parse) models = this.parse(models, options);
|
||||||
var model, i, l, existing;
|
var attrs, model, i, l, existing;
|
||||||
var add = [], remove = [], modelMap = {};
|
var add = [], remove = [], modelMap = {};
|
||||||
|
|
||||||
// Allow a single model (or no argument) to be passed.
|
// Allow a single model (or no argument) to be passed.
|
||||||
@@ -773,11 +781,12 @@
|
|||||||
|
|
||||||
// Determine which models to add and merge, and which to remove.
|
// Determine which models to add and merge, and which to remove.
|
||||||
for (i = 0, l = models.length; i < l; i++) {
|
for (i = 0, l = models.length; i < l; i++) {
|
||||||
model = models[i];
|
if (!((attrs = models[i]) instanceof Model)) attrs = _.clone(attrs);
|
||||||
|
if (!(model = this._prepareModel(attrs, options))) continue;
|
||||||
existing = this.get(model);
|
existing = this.get(model);
|
||||||
if (options.remove && existing) modelMap[existing.cid] = true;
|
if (options.remove && existing) modelMap[existing.cid] = true;
|
||||||
if ((options.add && !existing) || (options.merge && existing)) {
|
if ((options.add && !existing) || (options.merge && existing)) {
|
||||||
add.push(model);
|
add.push(models[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.remove) {
|
if (options.remove) {
|
||||||
@@ -816,11 +825,14 @@
|
|||||||
options = options ? _.clone(options) : {};
|
options = options ? _.clone(options) : {};
|
||||||
if (options.parse === void 0) options.parse = true;
|
if (options.parse === void 0) options.parse = true;
|
||||||
var success = options.success;
|
var success = options.success;
|
||||||
options.success = function(collection, resp, options) {
|
var collection = this;
|
||||||
|
options.success = function(resp) {
|
||||||
var method = options.update ? 'update' : 'reset';
|
var method = options.update ? 'update' : 'reset';
|
||||||
collection[method](resp, options);
|
collection[method](resp, options);
|
||||||
if (success) success(collection, resp, options);
|
if (success) success(collection, resp, options);
|
||||||
|
collection.trigger('sync', collection, resp, options);
|
||||||
};
|
};
|
||||||
|
wrapError(this, options);
|
||||||
return this.sync('read', this, options);
|
return this.sync('read', this, options);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -833,7 +845,7 @@
|
|||||||
if (!options.wait) this.add(model, options);
|
if (!options.wait) this.add(model, options);
|
||||||
var collection = this;
|
var collection = this;
|
||||||
var success = options.success;
|
var success = options.success;
|
||||||
options.success = function(model, resp, options) {
|
options.success = function(resp) {
|
||||||
if (options.wait) collection.add(model, options);
|
if (options.wait) collection.add(model, options);
|
||||||
if (success) success(model, resp, options);
|
if (success) success(model, resp, options);
|
||||||
};
|
};
|
||||||
@@ -868,7 +880,10 @@
|
|||||||
options || (options = {});
|
options || (options = {});
|
||||||
options.collection = this;
|
options.collection = this;
|
||||||
var model = new this.model(attrs, options);
|
var model = new this.model(attrs, options);
|
||||||
if (!model._validate(attrs, options)) return false;
|
if (!model._validate(attrs, options)) {
|
||||||
|
this.trigger('invalid', this, attrs, options);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return model;
|
return model;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1432,18 +1447,6 @@
|
|||||||
params.processData = false;
|
params.processData = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var success = options.success;
|
|
||||||
options.success = function(resp) {
|
|
||||||
if (success) success(model, resp, options);
|
|
||||||
model.trigger('sync', model, resp, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
var error = options.error;
|
|
||||||
options.error = function(xhr) {
|
|
||||||
if (error) error(model, xhr, options);
|
|
||||||
model.trigger('error', model, xhr, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Make the request, allowing the user to override any Ajax options.
|
// Make the request, allowing the user to override any Ajax options.
|
||||||
var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
|
var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
|
||||||
model.trigger('request', model, xhr, options);
|
model.trigger('request', model, xhr, options);
|
||||||
@@ -1502,4 +1505,13 @@
|
|||||||
throw new Error('A "url" property or function must be specified');
|
throw new Error('A "url" property or function must be specified');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Wrap an optional error callback with a fallback error event.
|
||||||
|
var wrapError = function (model, options) {
|
||||||
|
var error = options.error;
|
||||||
|
options.error = function(resp) {
|
||||||
|
if (error) error(model, resp, options);
|
||||||
|
model.trigger('error', model, resp, options);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|||||||
83
vendor/backbone/test/collection.js
vendored
83
vendor/backbone/test/collection.js
vendored
@@ -70,22 +70,20 @@ $(document).ready(function() {
|
|||||||
equal(col.get(col.first().cid), col.first());
|
equal(col.get(col.first().cid), col.first());
|
||||||
});
|
});
|
||||||
|
|
||||||
test("get with non-default ids", 4, function() {
|
test("get with non-default ids", 5, function() {
|
||||||
var col = new Backbone.Collection();
|
var col = new Backbone.Collection();
|
||||||
var MongoModel = Backbone.Model.extend({
|
var MongoModel = Backbone.Model.extend({idAttribute: '_id'});
|
||||||
idAttribute: '_id'
|
|
||||||
});
|
|
||||||
var model = new MongoModel({_id: 100});
|
var model = new MongoModel({_id: 100});
|
||||||
col.push(model);
|
col.add(model);
|
||||||
equal(col.get(100), model);
|
equal(col.get(100), model);
|
||||||
model.set({_id: 101});
|
equal(col.get(model.cid), model);
|
||||||
equal(col.get(101), model);
|
equal(col.get(model), model);
|
||||||
|
equal(col.get(101), void 0);
|
||||||
|
|
||||||
var Col2 = Backbone.Collection.extend({ model: MongoModel });
|
var col2 = new Backbone.Collection();
|
||||||
var col2 = new Col2();
|
col2.model = MongoModel;
|
||||||
col2.push(model);
|
col2.add(model.attributes);
|
||||||
equal(col2.get({_id: 101}), model);
|
equal(col2.get(model.clone()), col2.first());
|
||||||
equal(col2.get(model.clone()), model);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("update index when id changes", 3, function() {
|
test("update index when id changes", 3, function() {
|
||||||
@@ -362,9 +360,7 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
test("model destroy removes from all collections", 3, function() {
|
test("model destroy removes from all collections", 3, function() {
|
||||||
var e = new Backbone.Model({id: 5, title: 'Othello'});
|
var e = new Backbone.Model({id: 5, title: 'Othello'});
|
||||||
e.sync = function(method, model, options) {
|
e.sync = function(method, model, options) { options.success(); };
|
||||||
options.success(model, [], options);
|
|
||||||
};
|
|
||||||
var colE = new Backbone.Collection([e]);
|
var colE = new Backbone.Collection([e]);
|
||||||
var colF = new Backbone.Collection([e]);
|
var colF = new Backbone.Collection([e]);
|
||||||
e.destroy();
|
e.destroy();
|
||||||
@@ -396,6 +392,15 @@ $(document).ready(function() {
|
|||||||
equal(this.syncArgs.options.parse, false);
|
equal(this.syncArgs.options.parse, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("fetch with an error response triggers an error event", 1, function () {
|
||||||
|
var collection = new Backbone.Collection();
|
||||||
|
collection.on('error', function () {
|
||||||
|
ok(true);
|
||||||
|
});
|
||||||
|
collection.sync = function (method, model, options) { options.error(); };
|
||||||
|
collection.fetch();
|
||||||
|
});
|
||||||
|
|
||||||
test("ensure fetch only parses once", 1, function() {
|
test("ensure fetch only parses once", 1, function() {
|
||||||
var collection = new Backbone.Collection;
|
var collection = new Backbone.Collection;
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
@@ -405,7 +410,7 @@ $(document).ready(function() {
|
|||||||
};
|
};
|
||||||
collection.url = '/test';
|
collection.url = '/test';
|
||||||
collection.fetch();
|
collection.fetch();
|
||||||
this.syncArgs.options.success([]);
|
this.syncArgs.options.success();
|
||||||
equal(counter, 1);
|
equal(counter, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -461,9 +466,10 @@ $(document).ready(function() {
|
|||||||
equal(JSON.stringify(col), '[{"id":3,"label":"a"},{"id":2,"label":"b"},{"id":1,"label":"c"},{"id":0,"label":"d"}]');
|
equal(JSON.stringify(col), '[{"id":3,"label":"a"},{"id":2,"label":"b"},{"id":1,"label":"c"},{"id":0,"label":"d"}]');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("where", 6, function() {
|
test("where and findWhere", 8, function() {
|
||||||
|
var model = new Backbone.Model({a: 1});
|
||||||
var coll = new Backbone.Collection([
|
var coll = new Backbone.Collection([
|
||||||
{a: 1},
|
model,
|
||||||
{a: 1},
|
{a: 1},
|
||||||
{a: 1, b: 2},
|
{a: 1, b: 2},
|
||||||
{a: 2, b: 2},
|
{a: 2, b: 2},
|
||||||
@@ -475,6 +481,8 @@ $(document).ready(function() {
|
|||||||
equal(coll.where({b: 1}).length, 0);
|
equal(coll.where({b: 1}).length, 0);
|
||||||
equal(coll.where({b: 2}).length, 2);
|
equal(coll.where({b: 2}).length, 2);
|
||||||
equal(coll.where({a: 1, b: 2}).length, 1);
|
equal(coll.where({a: 1, b: 2}).length, 1);
|
||||||
|
equal(coll.findWhere({a: 1}), model);
|
||||||
|
equal(coll.findWhere({a: 4}), void 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Underscore methods", 13, function() {
|
test("Underscore methods", 13, function() {
|
||||||
@@ -484,10 +492,10 @@ $(document).ready(function() {
|
|||||||
equal(col.indexOf(b), 1);
|
equal(col.indexOf(b), 1);
|
||||||
equal(col.size(), 4);
|
equal(col.size(), 4);
|
||||||
equal(col.rest().length, 3);
|
equal(col.rest().length, 3);
|
||||||
ok(!_.include(col.rest()), a);
|
ok(!_.include(col.rest(), a));
|
||||||
ok(!_.include(col.rest()), d);
|
ok(_.include(col.rest(), d));
|
||||||
ok(!col.isEmpty());
|
ok(!col.isEmpty());
|
||||||
ok(!_.include(col.without(d)), d);
|
ok(!_.include(col.without(d), d));
|
||||||
equal(col.max(function(model){ return model.id; }).id, 3);
|
equal(col.max(function(model){ return model.id; }).id, 3);
|
||||||
equal(col.min(function(model){ return model.id; }).id, 0);
|
equal(col.min(function(model){ return model.id; }).id, 0);
|
||||||
deepEqual(col.chain()
|
deepEqual(col.chain()
|
||||||
@@ -702,9 +710,7 @@ $(document).ready(function() {
|
|||||||
test("#1447 - create with wait adds model.", 1, function() {
|
test("#1447 - create with wait adds model.", 1, function() {
|
||||||
var collection = new Backbone.Collection;
|
var collection = new Backbone.Collection;
|
||||||
var model = new Backbone.Model;
|
var model = new Backbone.Model;
|
||||||
model.sync = function(method, model, options){
|
model.sync = function(method, model, options){ options.success(); };
|
||||||
options.success(model, [], options);
|
|
||||||
};
|
|
||||||
collection.on('add', function(){ ok(true); });
|
collection.on('add', function(){ ok(true); });
|
||||||
collection.create(model, {wait: true});
|
collection.create(model, {wait: true});
|
||||||
});
|
});
|
||||||
@@ -928,6 +934,35 @@ $(document).ready(function() {
|
|||||||
equal(col.length, 1);
|
equal(col.length, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("`update` and model level `parse`", function() {
|
||||||
|
var Model = Backbone.Model.extend({
|
||||||
|
parse: function (res) { return res.model; }
|
||||||
|
});
|
||||||
|
var Collection = Backbone.Collection.extend({
|
||||||
|
model: Model,
|
||||||
|
parse: function (res) { return res.models; }
|
||||||
|
});
|
||||||
|
var model = new Model({id: 1});
|
||||||
|
var collection = new Collection(model);
|
||||||
|
collection.update({models: [
|
||||||
|
{model: {id: 1}},
|
||||||
|
{model: {id: 2}}
|
||||||
|
]}, {parse: true});
|
||||||
|
equal(collection.first(), model);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("`update` data is only parsed once", function() {
|
||||||
|
var collection = new Backbone.Collection();
|
||||||
|
collection.model = Backbone.Model.extend({
|
||||||
|
parse: function (data) {
|
||||||
|
equal(data.parsed, void 0);
|
||||||
|
data.parsed = true;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
collection.update({}, {parse: true});
|
||||||
|
});
|
||||||
|
|
||||||
test("#1894 - Push should not trigger a sort", 0, function() {
|
test("#1894 - Push should not trigger a sort", 0, function() {
|
||||||
var Collection = Backbone.Collection.extend({
|
var Collection = Backbone.Collection.extend({
|
||||||
comparator: 'id',
|
comparator: 'id',
|
||||||
|
|||||||
5
vendor/backbone/test/events.js
vendored
5
vendor/backbone/test/events.js
vendored
@@ -99,6 +99,11 @@ $(document).ready(function() {
|
|||||||
a.listenTo(b, 'event2', cb);
|
a.listenTo(b, 'event2', cb);
|
||||||
a.stopListening(null, {event: cb});
|
a.stopListening(null, {event: cb});
|
||||||
b.trigger('event event2');
|
b.trigger('event event2');
|
||||||
|
b.off();
|
||||||
|
a.listenTo(b, 'event event2', cb);
|
||||||
|
a.stopListening(null, 'event');
|
||||||
|
a.stopListening();
|
||||||
|
b.trigger('event2');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("listenToOnce and stopListening", 1, function() {
|
test("listenToOnce and stopListening", 1, function() {
|
||||||
|
|||||||
30
vendor/backbone/test/model.js
vendored
30
vendor/backbone/test/model.js
vendored
@@ -401,7 +401,7 @@ $(document).ready(function() {
|
|||||||
if (attrs.admin) return "Can't change admin status.";
|
if (attrs.admin) return "Can't change admin status.";
|
||||||
};
|
};
|
||||||
model.sync = function(method, model, options) {
|
model.sync = function(method, model, options) {
|
||||||
options.success.call(this, this, {admin: true}, options);
|
options.success.call(this, {admin: true});
|
||||||
};
|
};
|
||||||
model.on('invalid', function(model, error) {
|
model.on('invalid', function(model, error) {
|
||||||
lastError = error;
|
lastError = error;
|
||||||
@@ -418,6 +418,19 @@ $(document).ready(function() {
|
|||||||
ok(_.isEqual(this.syncArgs.model, doc));
|
ok(_.isEqual(this.syncArgs.model, doc));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("save, fetch, destroy triggers error event when an error occurs", 3, function () {
|
||||||
|
var model = new Backbone.Model();
|
||||||
|
model.on('error', function () {
|
||||||
|
ok(true);
|
||||||
|
});
|
||||||
|
model.sync = function (method, model, options) {
|
||||||
|
options.error();
|
||||||
|
};
|
||||||
|
model.save({data: 2, id: 1});
|
||||||
|
model.fetch();
|
||||||
|
model.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
test("save with PATCH", function() {
|
test("save with PATCH", function() {
|
||||||
doc.clear().set({id: 1, a: 1, b: 2, c: 3, d: 4});
|
doc.clear().set({id: 1, a: 1, b: 2, c: 3, d: 4});
|
||||||
doc.save();
|
doc.save();
|
||||||
@@ -435,7 +448,7 @@ $(document).ready(function() {
|
|||||||
test("save in positional style", 1, function() {
|
test("save in positional style", 1, function() {
|
||||||
var model = new Backbone.Model();
|
var model = new Backbone.Model();
|
||||||
model.sync = function(method, model, options) {
|
model.sync = function(method, model, options) {
|
||||||
options.success(model, {}, options);
|
options.success();
|
||||||
};
|
};
|
||||||
model.save('title', 'Twelfth Night');
|
model.save('title', 'Twelfth Night');
|
||||||
equal(model.get('title'), 'Twelfth Night');
|
equal(model.get('title'), 'Twelfth Night');
|
||||||
@@ -444,8 +457,8 @@ $(document).ready(function() {
|
|||||||
test("save with non-object success response", 2, function () {
|
test("save with non-object success response", 2, function () {
|
||||||
var model = new Backbone.Model();
|
var model = new Backbone.Model();
|
||||||
model.sync = function(method, model, options) {
|
model.sync = function(method, model, options) {
|
||||||
options.success(model, '', options);
|
options.success('', options);
|
||||||
options.success(model, null, options);
|
options.success(null, options);
|
||||||
};
|
};
|
||||||
model.save({testing:'empty'}, {
|
model.save({testing:'empty'}, {
|
||||||
success: function (model) {
|
success: function (model) {
|
||||||
@@ -720,7 +733,7 @@ $(document).ready(function() {
|
|||||||
test("#1030 - `save` with `wait` results in correct attributes if success is called during sync", 2, function() {
|
test("#1030 - `save` with `wait` results in correct attributes if success is called during sync", 2, function() {
|
||||||
var model = new Backbone.Model({x: 1, y: 2});
|
var model = new Backbone.Model({x: 1, y: 2});
|
||||||
model.sync = function(method, model, options) {
|
model.sync = function(method, model, options) {
|
||||||
options.success(model, {}, options);
|
options.success();
|
||||||
};
|
};
|
||||||
model.on("change:x", function() { ok(true); });
|
model.on("change:x", function() { ok(true); });
|
||||||
model.save({x: 3}, {wait: true});
|
model.save({x: 3}, {wait: true});
|
||||||
@@ -893,7 +906,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
model.sync = function(method, model, options) {
|
model.sync = function(method, model, options) {
|
||||||
options.success(model, {}, options);
|
options.success();
|
||||||
};
|
};
|
||||||
model.save({id: 1}, opts);
|
model.save({id: 1}, opts);
|
||||||
model.fetch(opts);
|
model.fetch(opts);
|
||||||
@@ -902,9 +915,8 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
test("#1412 - Trigger 'sync' event.", 3, function() {
|
test("#1412 - Trigger 'sync' event.", 3, function() {
|
||||||
var model = new Backbone.Model({id: 1});
|
var model = new Backbone.Model({id: 1});
|
||||||
model.url = '/test';
|
model.sync = function (method, model, options) { options.success(); };
|
||||||
model.on('sync', function(){ ok(true); });
|
model.on('sync', function(){ ok(true); });
|
||||||
Backbone.ajax = function(settings){ settings.success(); };
|
|
||||||
model.fetch();
|
model.fetch();
|
||||||
model.save();
|
model.save();
|
||||||
model.destroy();
|
model.destroy();
|
||||||
@@ -950,7 +962,7 @@ $(document).ready(function() {
|
|||||||
var Model = Backbone.Model.extend({
|
var Model = Backbone.Model.extend({
|
||||||
sync: function(method, model, options) {
|
sync: function(method, model, options) {
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
options.success(model, {}, options);
|
options.success();
|
||||||
start();
|
start();
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user