Merge branch 'master' into collection-update

Conflicts:
	test/collection.js
This commit is contained in:
Casey Foster
2012-12-05 10:31:31 -08:00
8 changed files with 75 additions and 1736 deletions

View File

@@ -588,10 +588,7 @@
if (options.comparator !== void 0) this.comparator = options.comparator;
this._reset();
this.initialize.apply(this, arguments);
if (models) {
if (options.parse) models = this.parse(models);
this.reset(models, {silent: true, parse: options.parse});
}
if (models) this.reset(models, _.extend({silent: true}, options));
};
// Define the Collection's inheritable methods.
@@ -619,7 +616,7 @@
// Add a model, or list of models to the set. Pass **silent** to avoid
// firing the `add` event for every new model.
add: function(models, options) {
var i, args, length, model, existing;
var i, args, length, model, existing, sort;
var at = options && options.at;
models = _.isArray(models) ? models.slice() : [models];
@@ -639,6 +636,7 @@
if (existing || this._byCid[model.cid]) {
if (options && options.merge && existing) {
existing.set(model, options);
sort = true;
}
models.splice(i, 1);
continue;
@@ -651,14 +649,15 @@
if (model.id != null) this._byId[model.id] = model;
}
// Update `length` and splice in new models.
// See if sorting is needed, update `length` and splice in new models.
if (models.length) sort = true;
this.length += models.length;
args = [at != null ? at : this.models.length, 0];
push.apply(args, models);
splice.apply(this.models, args);
// Sort the collection if appropriate.
if (this.comparator && at == null) this.sort({silent: true});
if (sort && this.comparator && at == null) this.sort({silent: true});
if (options && options.silent) return this;
@@ -800,6 +799,7 @@
// you can reset the entire set with a new list of models, without firing
// any `add` or `remove` events. Fires `reset` when finished.
reset: function(models, options) {
if (options && options.parse) models = this.parse(models);
for (var i = 0, l = this.models.length; i < l; i++) {
this._removeReference(this.models[i]);
}

BIN
docs/images/jolicloud.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

View File

@@ -470,6 +470,7 @@
<li> <a href="#examples-easel">Easel</a></li>
<li> <a href="#examples-prose">Prose</a></li>
<li> <a href="#examples-scrollkit">scroll kit</a></li>
<li>- <a href="#examples-jolicloud">Jolicloud</a></li>
<li> <a href="#examples-battlefield">Battlefield Play4Free</a></li>
<li> <a href="#examples-syllabus">Syllabus</a></li>
<li> <a href="#examples-salon">Salon.io</a></li>
@@ -3217,21 +3218,24 @@ var model = localBackbone.Model.extend(...);
</a>
</div>
<h2 id="examples-scrollkit">scroll kit</h2>
<h2 id="examples-jolicloud">Jolicloud</h2>
<p>
<a href="http://scrollkit.com/">scroll kit</a> is a new kind of website
builder that makes designing a web page feel more like drawing.
The workspace is a single-page web application built with Rails and Backbone.js.
In scroll kit, every DOM element is associated with a Backbone model, so that
style changes that are made to an element automatically update the model
and propagate the change across all its views.
<a href="http://scrollkit.com/demo">Try it out</a>.
<a href="http://www.jolicloud.com/">Jolicloud</a> is an open and independent
platform and <a href="http://www.jolicloud.com/jolios">operating system</a>
that provides music playback, video streaming, photo browsing and
document editing &mdash; transforming low cost computers into beautiful cloud devices.
The <a href="https://my.jolicloud.com/">new Jolicloud HTML5 app</a> was built
from the ground up using Backbone and talks to the
<a href="http://developers.jolicloud.com">Jolicloud Platform</a>, which is
based on Node.js. Jolicloud works offline using the HTML5 AppCache, extends
Backbone.sync to store data in IndexedDB or localStorage, and communicates
with the <a href="http://www.jolicloud.com/jolios">Joli OS</a> via WebSockets.
</p>
<div style="text-align: center;">
<a href="http://scrollkit.com">
<img width="550" height="453" data-original="docs/images/scrollkit.png" alt="scroll kit" class="example_image" />
<a href="http://jolicloud.com/">
<img width="510" height="384" data-original="docs/images/jolicloud.jpg" alt="Jolicloud" class="example_retina" />
</a>
</div>

View File

@@ -715,6 +715,60 @@ $(document).ready(function() {
this.ajaxSettings.success([model]);
});
test("`sort` shouldn't always fire on `add`", 1, function() {
var c = new Backbone.Collection([{id: 1}, {id: 2}, {id: 3}], {
comparator: 'id'
});
c.sort = function(){ ok(true); };
c.add([]);
c.add({id: 1});
c.add([{id: 2}, {id: 3}]);
c.add({id: 4});
});
test("#1407 parse option on constructor parses collection and models", 2, function() {
var model = {
namespace : [{id: 1}, {id:2}]
};
var Collection = Backbone.Collection.extend({
model: Backbone.Model.extend({
parse: function(model) {
model.name = 'test';
return model;
}
}),
parse: function(model) {
return model.namespace;
}
});
var c = new Collection(model, {parse:true});
equal(c.length, 2);
equal(c.at(0).get('name'), 'test');
});
test("#1407 parse option on reset parses collection and models", 2, function() {
var model = {
namespace : [{id: 1}, {id:2}]
};
var Collection = Backbone.Collection.extend({
model: Backbone.Model.extend({
parse: function(model) {
model.name = 'test';
return model;
}
}),
parse: function(model) {
return model.namespace;
}
});
var c = new Collection();
c.reset(model, {parse:true});
equal(c.length, 2);
equal(c.at(0).get('name'), 'test');
});
test("update", 5, function() {
var m1 = new Backbone.Model;
var m2 = new Backbone.Model({id: 2});

View File

@@ -19,17 +19,6 @@
<script src="view.js"></script>
<script src="sync.js"></script>
<script src="speed.js"></script>
<script>
_.extend(QUnit.config, {
noglobals: true,
urlConfig: _.filter(QUnit.config.urlConfig, function(option) {
return option.id !== 'noglobals';
})
});
</script>
</head>
<body>
<div id="qunit"></div>

View File

@@ -1,30 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Backbone Test Suite</title>
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="vendor/json2.js"></script>
<script type="text/javascript" src="vendor/ender-jeesh.js"></script>
<script type="text/javascript" src="vendor/qunit.js"></script>
<script type="text/javascript" src="vendor/jslitmus.js"></script>
<script type="text/javascript" src="vendor/underscore.js"></script>
<script type="text/javascript" src="../backbone.js"></script>
<script type="text/javascript" src="events.js"></script>
<script type="text/javascript" src="model.js"></script>
<script type="text/javascript" src="collection.js"></script>
<script type="text/javascript" src="router.js"></script>
<script type="text/javascript" src="view.js"></script>
<script type="text/javascript" src="sync.js"></script>
<script type="text/javascript" src="speed.js"></script>
</head>
<body>
<h1 id="qunit-header">Backbone Test Suite</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<br /><br />
<h1 id="qunit-header"><a href="#">Backbone Speed Suite</a></h1>
<div id="jslitmus_container" style="margin: 20px 10px;"></div>
</body>
</html>

File diff suppressed because it is too large Load Diff