Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
backbone-nested-models
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
0976fcad
authored
2014-04-11 14:44:16 -0500
by
Ean Schuessler
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'BF-2608' of /home/git/repositories/brainfood/backbone-nested-models
2 parents
3a21b2ec
88d84fee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
4 deletions
src/scripts/backbone-nested-models.js
test/specs/backbone-nested-models.spec.js
src/scripts/backbone-nested-models.js
View file @
0976fca
...
...
@@ -83,13 +83,18 @@ define(
(
attrs
=
{})[
key
]
=
val
;
}
if
(
options
&&
options
.
merge
)
{
nestedOptions
=
{
silent
:
false
,
merge
:
true
};
nestedOptions
=
{
silent
:
false
,
merge
:
true
,
parse
:
options
.
parse
};
for
(
attr
in
attrs
)
{
curVal
=
this
.
get
(
attr
);
newVal
=
attrs
[
attr
];
if
(
curVal
instanceof
Backbone
.
Model
&&
newVal
instanceof
Backbone
.
Model
)
{
delete
attrs
[
attr
];
curVal
.
set
(
newVal
.
attributes
,
nestedOptions
);
if
(
curVal
instanceof
Backbone
.
Model
)
{
if
(
newVal
instanceof
Backbone
.
Model
)
{
delete
attrs
[
attr
];
curVal
.
set
(
newVal
.
attributes
,
nestedOptions
);
}
else
if
(
options
.
parse
&&
typeof
newVal
===
'object'
)
{
delete
attrs
[
attr
];
curVal
.
set
(
newVal
,
nestedOptions
);
}
}
}
}
...
...
test/specs/backbone-nested-models.spec.js
View file @
0976fca
...
...
@@ -189,6 +189,33 @@ define(function(require) {
}
else
{
expect
(
top
.
counts
).
toBeUndefined
();
}
result
=
top
.
set
(
'nested'
,
{
address1
:
'1234 Main St.'
},
{
merge
:
true
,
parse
:
true
});
expect
(
result
).
toBe
(
top
);
var
cidsSetnestedpojoparse
=
extractCids
(
top
);
expect
(
cidsSetnestedmerge
.
top
).
toEqual
(
cidsSetnestedpojoparse
.
top
);
expect
(
cidsSetnestedmerge
.
nested
).
toEqual
(
cidsSetnestedpojoparse
.
nested
);
expect
(
top
.
get
(
'name'
)).
toEqual
(
'value'
);
expect
(
top
.
get
(
'nested'
).
get
(
'address1'
)).
toEqual
(
'1234 Main St.'
);
if
(
checkCounts
)
{
expect
(
top
.
counts
).
toEqual
({
set
:
7
});
}
else
{
expect
(
top
.
counts
).
toBeUndefined
();
}
result
=
top
.
set
(
'nested'
,
{
address1
:
'4321 Main St.'
},
{
merge
:
true
});
expect
(
result
).
toBe
(
top
);
var
cidsSetnestedpojo
=
extractCids
(
top
);
expect
(
cidsSetnestedpojoparse
.
top
).
toEqual
(
cidsSetnestedpojo
.
top
);
expect
(
cidsSetnestedpojo
.
nested
).
toBeUndefined
();
expect
(
top
.
get
(
'name'
)).
toEqual
(
'value'
);
expect
(
top
.
get
(
'nested'
)).
not
.
toEqual
(
jasmine
.
any
(
Backbone
.
Model
));
expect
(
top
.
get
(
'nested'
).
address1
).
toEqual
(
'4321 Main St.'
);
if
(
checkCounts
)
{
expect
(
top
.
counts
).
toEqual
({
set
:
8
});
}
else
{
expect
(
top
.
counts
).
toBeUndefined
();
}
}
it
(
'set-mixin-plain'
,
function
()
{
testSet
.
call
(
this
,
NestedModels
.
mixin
(
Top
),
false
);
...
...
Please
register
or
sign in
to post a comment