-
Notifications
You must be signed in to change notification settings - Fork 49
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
DirtyFlag implementation #11
Comments
I had similar problems. In my case the isDirty and reset functions where added to the model. |
Feel free to create a pull request with a change. |
Problem: isDirty and reset functions where added to the model. Fixed it by moving the self-assignemnt out of the result function. So the this-Reference of the actual dirtyFlag-Object is saved in the variable self and when the result function is called later, the isDirty and reset functions are added to the dirtyFlag-Object.
This simple bug had me pulling my hair until i debugged and realized a reset function I created on my model was being replaced by the reset function in the dirtyFlag. @apircher good job on the pull request. |
If someone can write a unit test to confirm this, we'll go ahead and merge it in. |
I see a pull request which includes jasmine but it doesn't seem to be in your master branch. Should I just merge in the spec into a folder called test? |
Vitaliy1 's implementation of knockout.dirtyFlag.js worked for me; but what I think is the suggested code by apircher did not. I'm new to github, so sorry if I'm not interpreting apircher, correctly. |
On 6/14/2013 3:43 AM, apircher wrote:
In my case, the function that was was doing the dirty flag reset worked I'm not an expert in javascript, so maybe I could have coded around Best, |
Fixed in #17. |
The current implementation of DirtyFlag is not correct:
;(function (ko) {
ko.DirtyFlag = function (objectToTrack, isInitiallyDirty, hashFunction) {
When we create a dirty flag like this:
var dirtyFlag = new ko.DirtyFlag(data);
a new object that was created by the "new" keyword is not used inside ko.DirtyFlag function. The result function is only declared but not executed.
When we use the created dirtyFlag, e.g.:
dirtyFlag().isDirty();
the result function is called with the window object as a context, so isDirty and reset functions are attached to the window object. If there are two dirty flags on the page, each of them will attach its isDirty and reset functions to the same window object when they are called.
So, please debug your code before committing it.
I think, you wanted to do this:
;(function (ko) {
ko.DirtyFlag = function (objectToTrack, isInitiallyDirty, hashFunction) {
The text was updated successfully, but these errors were encountered: