New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update undoChanges method to accept an only option. #25
Changes from 1 commit
521c6b1
3520684
b3fb04c
6035d86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1033,6 +1033,8 @@ var Model = TransisObject.extend(function() { | |
// opts - An object containing zero or more of the following keys: | ||
// except - Either a string or an array of strings of owned association names to skip over when | ||
// undoing changes on owned associations. | ||
// only - Either a string or an array of strings of owned association names that limit the undoing of changes | ||
// to only the provided associations. | ||
// | ||
// Returns the receiver. | ||
this.prototype.undoChanges = function(opts = {}) { | ||
|
@@ -1059,6 +1061,9 @@ var Model = TransisObject.extend(function() { | |
if (opts.except === name) { continue; } | ||
if (Array.isArray(opts.except) && opts.except.indexOf(name) >= 0) { continue; } | ||
|
||
if (opts.only && opts.only !== name) { continue; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. How does this look?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That looks better. Make sure you add a spec for the scenario I described. |
||
if (Array.isArray(opts.only) && opts.only.indexOf(name) === -1) { continue; } | ||
|
||
if (desc.type === 'hasOne') { | ||
this[name] && this[name].undoChanges(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@burrows While working on the only option, noticed a bug with the except option. If you write the test this way it would fail. This is because the check was not happing in
for (let prop in this.ownChanges) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stallings Originally the
except
option was designed to only avoid recursively callingundoChanges
on associated objects. This change makes it work with attributes as well. I think this makes sense, but please update the documentation to reflect that.