Skip to content

Commit e01c57d

Browse files
committed
address original issue
1 parent 626adb6 commit e01c57d

File tree

4 files changed

+4
-36
lines changed

4 files changed

+4
-36
lines changed

3.0.0.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ Parse.Cloud.beforeSave('Post', function(request, response) {
5959
As we can see the current way, with backbone style callbacks is quite tough to read and maintain.
6060
It's also not really trivial to handle errors, as you need to pass the response.error to each error handlers.
6161

62-
Now it can be modernized with promises:
62+
Do not return in beforeSave hooks as this may have prevent the hook from working.
6363

6464
```js
6565
// after (with promises)
6666
Parse.Cloud.beforeSave('MyClassName', (request) => {
67+
// Don't return here use await / async
6768
return Parse.Cloud.httpRequest({
6869
url: request.object.get('fileURL')
6970
}).then((contents) => {

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ For more informations, visit the v3.0.0 [migration guide](https://github.com/par
4444

4545
#### Breaking changes:
4646
* Cloud Code handlers have a new interface based on promises.
47+
* Returning in before hooks are deprecated.
4748
* response.success / response.error are removed in Cloud Code
4849
* Cloud Code runs with Parse-SDK 2.0
4950
* The aggregate now require aggregates to be passed in the form: `{"pipeline": [...]}`

spec/CloudCode.spec.js

-25
Original file line numberDiff line numberDiff line change
@@ -193,31 +193,6 @@ describe('Cloud Code', () => {
193193
});
194194
});
195195

196-
it('test beforeSave applies changes and resolves returned promise', done => {
197-
Parse.Cloud.beforeSave('Insurance', function(req) {
198-
req.object.set('rate', '$49.99/Month');
199-
return new Parse.Query('Pet').get(req.object.get('pet').id).then(pet => {
200-
pet.set('healthy', true);
201-
return pet.save();
202-
});
203-
});
204-
205-
const pet = new Parse.Object('Pet');
206-
pet.set('healthy', false);
207-
pet.save().then(pet => {
208-
const insurance = new Parse.Object('Insurance');
209-
insurance.set('pet', pet);
210-
insurance.set('rate', '$5.00/Month');
211-
insurance.save().then(insurance => {
212-
expect(insurance.get('rate')).toEqual('$49.99/Month');
213-
new Parse.Query('Pet').get(insurance.get('pet').id).then(pet => {
214-
expect(pet.get('healthy')).toEqual(true);
215-
done();
216-
});
217-
});
218-
});
219-
});
220-
221196
it('test afterSave ran and created an object', function(done) {
222197
Parse.Cloud.afterSave('AfterSaveTest', function(req) {
223198
const obj = new Parse.Object('AfterSaveProof');

src/triggers.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export function getResponseObject(request, resolve, reject) {
254254
// Use the JSON response
255255
if (
256256
response &&
257+
typeof response === 'object' &&
257258
!request.object.equals(response) &&
258259
request.triggerName === Types.beforeSave
259260
) {
@@ -573,16 +574,6 @@ export function maybeRunTrigger(
573574
auth
574575
);
575576
}
576-
577-
// beforeSave is expected to return null (nothing)
578-
if (triggerType === Types.beforeSave) {
579-
// if the beforeSave returned a promise, return null after the promise is resolved
580-
if (promise && typeof promise.then === 'function') {
581-
return promise.then(() => null);
582-
}
583-
return null;
584-
}
585-
586577
return promise;
587578
})
588579
.then(success, error);

0 commit comments

Comments
 (0)