[Pkg-javascript-commits] [backbone] 14/211: Adding Collection#fetch with add: true
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 16:59:57 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.5.0
in repository backbone.
commit 784adc625d8d09a35f57891803c772c7bdd94e85
Merge: 0c1bbbc 3623916
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Wed Dec 8 13:14:05 2010 -0500
Adding Collection#fetch with add: true
backbone.js | 5 +++--
index.html | 13 ++++++++++---
2 files changed, 13 insertions(+), 5 deletions(-)
diff --cc backbone.js
index 5907a17,d124b94..ca0da18
--- a/backbone.js
+++ b/backbone.js
@@@ -481,16 -461,20 +481,17 @@@
},
// Fetch the default set of models for this collection, refreshing the
-- // collection when they arrive.
++ // collection when they arrive. If `add: true` is passed, appends the
++ // models to the collection instead of refreshing.
fetch : function(options) {
options || (options = {});
var collection = this;
var success = function(resp) {
- collection.refresh(collection.parse(resp));
- if(options.append) {
- collection.add(collection.parse(resp));
- } else {
- collection.refresh(collection.parse(resp));
- }
- if (options.success) options.success(collection, resp);
- };
- var error = options.error && _.bind(options.error, null, collection);
- Backbone.sync('read', this, success, error);
++ collection[options.add ? 'add' : 'refresh'](collection.parse(resp));
+ if (options.success) options.success(collection, resp);
+ };
+ var error = wrapError(options.error, collection, options);
+ (this.sync || Backbone.sync)('read', this, success, error);
return this;
},
diff --cc index.html
index ffc2b3a,5ed826c..0d25ea7
--- a/index.html
+++ b/index.html
@@@ -1252,11 -1206,11 +1252,18 @@@ Accounts.fetch()
</pre>
<p>
++ If you'd like to add the incoming models to the current collection, instead
++ of replacing the collection's contents, pass <tt>{add: true}</tt> as an
++ option to <b>fetch</b>.
++ </p>
++
++ <p>
Note that <b>fetch</b> should not be used to populate collections on
page load — all models needed at load time should already be
-- bootstrapped in to place. <b>fetch</b> is intended for lazily-loading models
-- for interfaces that are not needed immediately: for example, documents
-- with collections of notes that may be toggled open and closed.
++ <a href="#FAQ-bootstrap">bootstrapped</a> in to place. <b>fetch</b> is
++ intended for lazily-loading models for interfaces that are not needed
++ immediately: for example, documents with collections of notes that may be
++ toggled open and closed.
</p>
<p id="Collection-refresh">
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list