Skip to content
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

Now $modified recurse on objects #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/angular-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,25 @@ angular.module('ur.model', []).provider('model', function() {
* @returns {object} Map of the fields that have been changed from the $pristine version
*/
$modified: function() {
var original = this.$original(), diff = {};
var actual = arguments[0] || this;
var original = arguments[1] || this.$original();

for (var prop in this) {
if (isFunc(this[prop])) {
var diff = {};
var props = {};

for (var prop in actual) {
if (isFunc(actual[prop])) {
continue;
}

if (!equals(this[prop], original[prop])) {
diff[prop] = this[prop];
if(isObject(actual[prop])) {
props = this.$modified(actual[prop], original[prop])
if(Object.keys(props).length > 0) {
diff[prop] = props;
}
}
else if (!equals(actual[prop], original[prop])) {
diff[prop] = actual[prop];
}
}

Expand Down