backbone-nested-attributes 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTc0NWRjODcwNGY4Y2I5NDZiMzhiY2IzZmFkN2RkZjk2Yjg3MGQyYw==
4
+ MmUwMTJjNzYyMmEzMjk1MmJhN2QyYjE2ZmI5ODIzNTllNjg5MmU5NQ==
5
5
  data.tar.gz: !binary |-
6
- MWNiZjc0NTdhMWY4NDQ0MzdjZjY0ZWVkYWM2YmVkNmZjZTFiZjRmZQ==
6
+ ZDc3OGE2YzI1MzI5Zjg2ZGEzM2U0MTBhNWM3ZDdkYTQyNmJiYzRjYQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YTkxMGM5ODQzMjgxMjc2NjBmNDIzYzhhY2JhM2JjZDI3NTdhNWI2M2EzNGY2
10
- Nzg3ODQ5ZDM5MTRmYTdiYzA4NDZmOTFmNDgwNzkyNzM3NzYzOTI2MzIxNjk1
11
- M2Y5YTdhZDJhMzQzZDJhMzA2MDEyMjQ2MjhkMjc4Y2JhNGMwYzM=
9
+ NzAwZGU5YThmOWUzMDc1MDRjZTAxODg0NDdmMWVhY2Y4YTdmNjIwYWU2NjRh
10
+ MDJmYjk3YWQzMzBiMmFmMTdhNmVkMTUyM2IxZWE2YzNhYjAyOGU5NTg0Nzgx
11
+ YmZkNWM0NGQ4NWQyYTNkZjI5YjhiNzgzYmY2YjIzMjZmYjAxZTE=
12
12
  data.tar.gz: !binary |-
13
- NTZkZjc0OTU0OWE3ZjQ2MDM1ZTkwYzVmMTYyYTcyZjdiMjc4MGQwYjMzODE0
14
- MzQ0OTE5YWNhMmZiZGM5NTViZDU4NGY3Y2JkYTcyZTU3MDM0YzU2Mzk1ZDJh
15
- ZGI5OTMwMmFhZDEyNDFmZGMxODVmZmIyNmI1Mjc3MDRhZGQ5MDQ=
13
+ YjA4NWY0ZjQ2OGI1MGQ2YjY0OGI3NjNkNTliZGE5N2U3N2ZmMTJhNTRkYTBi
14
+ NDcyZWUzOWRlZTAzZDE1NGIyMjEwYzVjMWJlOWYyM2QyODYyMzgwMjVhZjJh
15
+ ZDQwZWE0NjU3NDBlOGVjMjI2NWViYjBlODMzY2U4OTI1YTRmYWU=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- backbone-nested-attributes (0.4.2)
4
+ backbone-nested-attributes (0.4.3)
5
5
  rails (>= 3.2.8)
6
6
 
7
7
  GEM
@@ -1,9 +1,7 @@
1
1
  (function(Backbone, _) {
2
2
  var BackboneModelPrototype = Backbone.Model.prototype
3
3
 
4
- function setNestedAttributes(model, key, value, options) {
5
- var attributes = attributesFor(key, value, options)
6
-
4
+ function setNestedAttributes(model, attributes) {
7
5
  if (attributes) {
8
6
  _(model.relations).each(function (relation) {
9
7
  if (relation.type == 'one') {
@@ -185,8 +183,19 @@
185
183
 
186
184
  Backbone.NestedAttributesModel = Backbone.Model.extend({
187
185
  set: function (key, value, options) {
188
- var attributes = setNestedAttributes(this, key, value, options)
189
- return BackboneModelPrototype.set.call(this, attributes, options)
186
+ var attributes
187
+
188
+ // Duplicate backbone's behavior to allow separate key/value parameters,
189
+ // instead of a single 'attributes' object.
190
+ if (_.isObject(key) || key == null) {
191
+ attributes = key
192
+ options = value
193
+ } else {
194
+ attributes = {}
195
+ attributes[key] = value
196
+ }
197
+
198
+ return BackboneModelPrototype.set.call(this, setNestedAttributes(this, attributes), options)
190
199
  },
191
200
 
192
201
  toJSON: function (options) {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2013-2014 Vicente Mundim
3
3
  *
4
- * Version: 0.4.2
4
+ * Version: 0.4.3
5
5
  *
6
6
  * MIT License
7
7
  *
@@ -34,9 +34,7 @@
34
34
  (function(Backbone, _) {
35
35
  var BackboneModelPrototype = Backbone.Model.prototype
36
36
 
37
- function setNestedAttributes(model, key, value, options) {
38
- var attributes = attributesFor(key, value, options)
39
-
37
+ function setNestedAttributes(model, attributes) {
40
38
  if (attributes) {
41
39
  _(model.relations).each(function (relation) {
42
40
  if (relation.type == 'one') {
@@ -218,8 +216,19 @@
218
216
 
219
217
  Backbone.NestedAttributesModel = Backbone.Model.extend({
220
218
  set: function (key, value, options) {
221
- var attributes = setNestedAttributes(this, key, value, options)
222
- return BackboneModelPrototype.set.call(this, attributes, options)
219
+ var attributes
220
+
221
+ // Duplicate backbone's behavior to allow separate key/value parameters,
222
+ // instead of a single 'attributes' object.
223
+ if (_.isObject(key) || key == null) {
224
+ attributes = key
225
+ options = value
226
+ } else {
227
+ attributes = {}
228
+ attributes[key] = value
229
+ }
230
+
231
+ return BackboneModelPrototype.set.call(this, setNestedAttributes(this, attributes), options)
223
232
  },
224
233
 
225
234
  toJSON: function (options) {
data/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backbone-nested-attributes",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "main": "backbone-nested-attributes.js",
5
5
  "description": "Add Rails-like nested attributes support for Backbone.Model.",
6
6
  "license": "MIT",
@@ -1,5 +1,5 @@
1
1
  module Backbone
2
2
  module NestedAttributes
3
- VERSION = "0.4.2"
3
+ VERSION = "0.4.3"
4
4
  end
5
5
  end
@@ -88,6 +88,16 @@ describe("Backbone.NestedAttributesModel", function() {
88
88
  expect(author.get('name')).toEqual('Jon Snow')
89
89
  })
90
90
 
91
+ it('pass options to original set', function (done) {
92
+ var called = false
93
+ model.on('change:title', function () { called = true })
94
+ model.set('title', 'My Title', { silent: true })
95
+ expect(called).toBeFalsy()
96
+
97
+ model.set({title: 'My New Title'}, { silent: true })
98
+ expect(called).toBeFalsy()
99
+ });
100
+
91
101
  describe("passing a model to the relation attribute", function() {
92
102
  beforeEach(function() {
93
103
  author = new Person({ name: 'Jon Snow' })
@@ -671,10 +681,7 @@ describe("Backbone.NestedAttributesModel", function() {
671
681
  model.get('comments').remove(comment)
672
682
  model.clear()
673
683
 
674
- expect(model.toJSON({ nested: true })).toEqual({
675
- title: undefined,
676
- comments_attributes: []
677
- })
684
+ expect(model.toJSON({ nested: true })).toEqual({})
678
685
  })
679
686
  })
680
687
  })
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backbone-nested-attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vicente Mundim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-15 00:00:00.000000000 Z
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails