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

response.success() does not return in beforeSave #1205

Closed
jiawenzhang opened this issue Mar 26, 2016 · 11 comments
Closed

response.success() does not return in beforeSave #1205

jiawenzhang opened this issue Mar 26, 2016 · 11 comments

Comments

@jiawenzhang
Copy link

Parse.Cloud.beforeSave("Item", function(request, response) {
  response.success();
  console.log("after response"); // this gets executed.
}

in parse.com, the beforeSave returns when response.success() is called, but in parse server, it does not.
tested on parse server 2.2.2

@flovilmart
Copy link
Contributor

yes it doesn't exit the current call stack. Is that a big problem for you?

@jiawenzhang
Copy link
Author

How to achieve the same effect as Paser.com? just call return?

@flovilmart
Copy link
Contributor

yes, call return response.success();

@tony-pizza
Copy link

tony-pizza commented May 18, 2016

Curious, what are the implications of running code after response.success() in a beforeSave, if any, (other than that it's funky)?

@drew-gross
Copy link
Contributor

The code will still execute, and you can still save object and etc. but the client will have already received the response. This can actually be useful in some cases, for example we use something like this when sending password reset emails.

@tony-pizza
Copy link

@drew-gross Ah, cool. Thanks. I want to send a Pusher event to clients notifying that an object was updated. Ideally I'd like send the event with info about which attributes changed so that the client only has to fetch the updates, but of course I only have that info in beforeSave. If I send the Pusher event before response.success() in beforeSave then there's a possible (though unlikely) race condition where the client receives the event and fetches the object, but the object hasn't been saved yet. Does that sound right? If I send the Pusher event after response.success() do I eliminate this race condition or does it still exist?

@drew-gross
Copy link
Contributor

If you want to ensure that the object has been saved, you need to run your logic in afterSave.

@tony-pizza
Copy link

@drew-gross that's what I figured. I just found out about request.original in afterSave so I can actually get the changed attributes in afterSave. Is request.original documented anywhere?

@drew-gross
Copy link
Contributor

Hmm I don't see any docs. Would you like to add some? Our docs are open source in the https://github.com/ParsePlatform/Docs repo

@tony-pizza
Copy link

@drew-gross okay, in here?

Are these docs no longer relevant for parse-server?

@drew-gross
Copy link
Contributor

Yep, thats right. The JS SDK docs are still relevant I think, but maybe you could check on the JS SDK repo if you want to delete them.

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

No branches or pull requests

4 participants