Comments (8)
i favor deprecating backbone style callbacks. i even created eslint rule for it. but i think total remove should be in 2.0.0
from parse-sdk-js.
i have a thought about after deprecation of the backbone
style callbacks:
maybe allow cloud functions to return Promise
instead of calls to response.success
/ response.error
.
it's a breaking change, but it might be more opinionated and strict and may let for a fewer errors:
// success
Parse.Cloud.define('ƒ', function(request) {
return {
"data": {···}
};
});
// success
Parse.Cloud.define('ƒ', function(request) {
return Promise.resolve(···);
});
// error
Parse.Cloud.define('ƒ', function(request) {
throw new Error(···);
});
// error
Parse.Cloud.define('ƒ', function(request) {
return Promise.reject(···);
});
// maybe error for undefined?
Parse.Cloud.define('ƒ', function(request) {});
also in the future when async
functions will be supported, it can lead to a very minimalistic API:
Parse.Cloud.define('ƒ', async function() {
const data = await ···;
···
return ···;
});
from parse-sdk-js.
Yeah, I think allowing cloud function to return promises would be an improvement. Would it even be a breaking change?... we could do something tricksy like behaving differently based on whether your function has one or two args. I think there's precedent for doing stuff like that in some node libraries.
from parse-sdk-js.
@lacker yep. my mistake. i forgot about Function.prototype.length
.
i think this thing can be improve for unit testing of the server side and also for deciding when to terminate the process of the function. also this pattern can be applied to other Cloud Code APIs as Parse.Cloud.BeforeSave
.
the thing i'm not sure of is the error part. for promises it's better to use a native Error
object which is different from Parse.Error
. i think this API can be problematic if Parse.Error
would stay the same (sadly we still cannot do that class ParseError extend Error {}
yet). and there are some questions about the error return value of the cloud function. Will Parse.Promise
convert Error
to Parse.Error
?
from parse-sdk-js.
It's too bad that ParseError can't just extend Error.
It seems like the promises shouldn't convert anything from one type to another. AFAICT the promise spec doesn't specify Error or anything, the promise spec just specifies that when something goes into "reject" or is thrown, it gets passed along like an error. Promises should work just as well if you just throw a string for example. I could be wrong there.
from parse-sdk-js.
@lacker it's true, but it will be a very weird behave for JavaScript developers to throw
a string
instead of Error
and it might be more difficult to handle in cases where you want Cloud Code and client side to share some code (specially third party). it's a conversion to throw Error
like objects and i can tell that i made lots of this kind mistakes when i've used response.error
with Error
or even Parse.Error
objects.
also throw
a string
doesn't return a stack
, which in many cases is needed (although it might be a security risk as well).
i think converting Error
s to the right needed response can be very beneficial specially for beginners
from parse-sdk-js.
Hmm, well so how about:
1/ Parse promises themselves would not convert data types at all
2/ But if you use cloud code with promises, and you either throw or reject something, when it goes to the client it will get transformed into a Parse.Error no matter what
That seems logical to me.
from parse-sdk-js.
Closed via #620
As of 2.0 of this SDK Backbone-style callbacks have been removed.
from parse-sdk-js.
Related Issues (20)
- Parse.Cloud.httpRequest is not a function HOT 2
- saveEventually - "code":209,"stack":"Error: Session token is expired" HOT 7
- Expand TypeScript support HOT 9
- Lock closed threads HOT 1
- saveEventually / EventuallyQueue doesn't work when killing server -> saveEventually object -> restarting server HOT 4
- API Reference Documentation not updated HOT 1
- SDK throws error in web contexts where calling into `window.indexedDB` is prohibited, but not undefined on the window HOT 2
- Calling `.add` multiple times on relations is broken HOT 4
- Refused to get unsafe header "access-control-expose-headers" on Chrome HOT 17
- Allow for REST Content Override for Server protection HOT 2
- Align currently supported Node.js version HOT 4
- `Parse.User.verifyPassword` does not pass request options to server HOT 5
- Parse SDK 4.3.1 is not working with React Native / Expo HOT 9
- Expo RN and ParseLiveQuery EventEmitter error HOT 13
- Cannot set ACL from JSON HOT 1
- Infinite loop in `encode.js` HOT 5
- Missing test for `Parse.User.verifyPassword` option `ignoreEmailVerification` HOT 2
- `Parse.Object.set` sliently handles validation errors HOT 1
- TypeError: attempted to use private field on non-instance, js engine: hermes HOT 3
- Installation support for JS SDK HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parse-sdk-js.