backbone-nested-attributes 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/app/assets/javascripts/backbone-nested-attributes/model.js +14 -5
- data/backbone-nested-attributes.js +15 -6
- data/bower.json +1 -1
- data/lib/backbone-nested-attributes/version.rb +1 -1
- data/spec/javascripts/backbone-nested-attributes/ModelSpec.js +11 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmUwMTJjNzYyMmEzMjk1MmJhN2QyYjE2ZmI5ODIzNTllNjg5MmU5NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDc3OGE2YzI1MzI5Zjg2ZGEzM2U0MTBhNWM3ZDdkYTQyNmJiYzRjYQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzAwZGU5YThmOWUzMDc1MDRjZTAxODg0NDdmMWVhY2Y4YTdmNjIwYWU2NjRh
|
10
|
+
MDJmYjk3YWQzMzBiMmFmMTdhNmVkMTUyM2IxZWE2YzNhYjAyOGU5NTg0Nzgx
|
11
|
+
YmZkNWM0NGQ4NWQyYTNkZjI5YjhiNzgzYmY2YjIzMjZmYjAxZTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjA4NWY0ZjQ2OGI1MGQ2YjY0OGI3NjNkNTliZGE5N2U3N2ZmMTJhNTRkYTBi
|
14
|
+
NDcyZWUzOWRlZTAzZDE1NGIyMjEwYzVjMWJlOWYyM2QyODYyMzgwMjVhZjJh
|
15
|
+
ZDQwZWE0NjU3NDBlOGVjMjI2NWViYjBlODMzY2U4OTI1YTRmYWU=
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
(function(Backbone, _) {
|
2
2
|
var BackboneModelPrototype = Backbone.Model.prototype
|
3
3
|
|
4
|
-
function setNestedAttributes(model,
|
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
|
189
|
-
|
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.
|
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,
|
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
|
222
|
-
|
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
@@ -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.
|
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-
|
11
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|