-
-
Notifications
You must be signed in to change notification settings - Fork 596
unable to save Object.fromJSON() because it's not dirty #161
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
Comments
This is by design -- when an object is constructed from a If you want to take the entire state of an object and send it to the server, you should construct an object like so:
This can be dangerous though. You should only be setting / saving the fields that have changed on your client. This is why we implement save the way we do. Here's an example: I have a Parse Object accessible from multiple devices (might be a web app and an iPhone app, might be multiple installations of the same app, does not matter).
If I only save the changes, both of them will be recorded on the server. If I save the entire object at once, though, the second device is not aware of the changes made by the first device. It sends the full copy of the object, and overwrites the changes made by the first object. Hope this makes sense! |
Hey @andrewimm. I use ParsePlatform in Vue and used ParseServerSDK. But there is a big problem as I told in link. I convert Parse Object to Json and change the some Json propery value and save. The Parse doesn't detect change. It save all value also didn't change value. So this is problem because same time, if anyone change value, this algorithm override value. |
exact same use case here(vue + parse) |
I’m not familiar with vue in particular, but I believe you should approach the problem differently. You should probably use an immutable state based on the server value, and the toJSON(). Then for recording mutation, you should treat them separately, and track them on a separate object. When you user wants to ‘save’ you apply all the mutations on the original object, save() and render your component again, based on the server response / object state |
@flovilmart Did you mean with "recording mutation", manually record somewhere changes or make a loop and detect which one change ? |
@dreadful44 yeah, basically your application state is the mix between the original object from the server + the list of mutations applied to the object. you can probably store the list of local mutation in a hashmap
Then the mutations can be just key / value pairs or a list of operations that the user performed on the top of the object (like This has many advantages like providing an undo / redo very easily (push / pop from the mutations array) I know this is working around the problem but it's a better strategy than sending back the whole object every times ;) |
Ok @flovilmart Thanks for your respond. I'll try. |
Hello!
I'm using Parse library within angular.js framework.
To bind parse object to Angular model, I'm using Parse.Object.toJSON() method.
Then, I need to update data on parse. To do this, I create new parse object using method Parse.Object.fromJSON({json}) and then call save() method.
I found that it sends to server only _updateAt field.
If I manually call "set" method on this object fields, parse starts working as expected.
I think, there is an issue with "dirty" fields.
The text was updated successfully, but these errors were encountered: