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

Updated isDirty function to check individual attributes #28

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Updated isDirty function to check individual attributes #28

wants to merge 5 commits into from

Conversation

thecountofzero
Copy link
Contributor

Re-worked previous attempt to allow for checking if an model attribute is dirty.

Updated the isDirty function to all for passing in a string (name of attribute).

Checking typeof arg. If "string" then we check the attribute for dirtiness. Otherwise proceed as usual.

@justinbmeyer
Copy link
Member

This should really use $.Object.same now ...

@thecountofzero
Copy link
Contributor Author

Trying to consume this.

How would I use $.Object.same to determine if a specific attribute of a model has been changed?

isDirty: function(option) {
// check if it serializes the same
if(!this._backupStore){
return false;
} else {
if(typeof option === "string") {
var current = this.attrs();
return current[option] ? $.Object.same(current[option], this._backupStore[option]) : false;
}
else return !same(this.serialize(), this._backupStore, !!option);
}
}

Or are you saying that it shouldn't even be in backup.js?

@justinbmeyer
Copy link
Member

What shouldn't be in backup?

Do you need to know the specific attribute?

@thecountofzero
Copy link
Contributor Author

The functionality that I was trying to provide was to give a way to determine if a specific attribute of a model has been changed (is dirty).

@justinbmeyer
Copy link
Member

ah ... hmmm. $.Object.same might need to be able to provide the attributes that are different.

@thecountofzero
Copy link
Contributor Author

Are you completely against having isDirty in backup.js defined as:

isDirty: function(option) {
    // check if it serializes the same
    if(!this._backupStore){
        return false;
    } else {
        if(typeof option === "string") {
            var current = this.attrs();         
            return current[option] !== this._backupStore[option] ? true : false;
        }
        else return !same(this.serialize(), this._backupStore, !!option);
    }
},

It works nicely and is simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants