[Pkg-javascript-commits] [backbone] 213/281: Fixes #570, supports Model#save(key, value)
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:02:14 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.9.0
in repository backbone.
commit 42d321f236f15ffeabe525a0358cc401467678ab
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Tue Jan 17 11:55:15 2012 -0500
Fixes #570, supports Model#save(key, value)
---
backbone.js | 11 ++++++++++-
test/model.js | 9 +++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/backbone.js b/backbone.js
index bb4ebf3..fa0dba7 100644
--- a/backbone.js
+++ b/backbone.js
@@ -291,7 +291,16 @@
// Set a hash of model attributes, and sync the model to the server.
// If the server returns an attributes hash that differs, the model's
// state will be `set` again.
- save : function(attrs, options) {
+ save : function(key, value, options) {
+ var attrs;
+ if (_.isObject(key) || key == null) {
+ attrs = key;
+ options = value;
+ } else {
+ attrs = {};
+ attrs[key] = value;
+ }
+
options = options ? _.clone(options) : {};
if (attrs && !this.set(attrs, options)) return false;
var model = this;
diff --git a/test/model.js b/test/model.js
index e60dba6..1980668 100644
--- a/test/model.js
+++ b/test/model.js
@@ -331,6 +331,15 @@ $(document).ready(function() {
ok(_.isEqual(lastRequest[1], doc));
});
+ test("Model: save in positional style", function() {
+ var model = new Backbone.Model();
+ model.sync = function(method, model, options) {
+ options.success();
+ };
+ model.save('title', 'Twelfth Night');
+ equals(model.get('title'), 'Twelfth Night');
+ });
+
test("Model: fetch", function() {
doc.fetch();
ok(lastRequest[0], 'read');
--
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