GithubHelp home page GithubHelp logo

Comments (8)

oriSomething avatar oriSomething commented on July 20, 2024

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.

oriSomething avatar oriSomething commented on July 20, 2024

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.

lacker avatar lacker commented on July 20, 2024

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.

oriSomething avatar oriSomething commented on July 20, 2024

@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.

lacker avatar lacker commented on July 20, 2024

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.

oriSomething avatar oriSomething commented on July 20, 2024

@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 Errors to the right needed response can be very beneficial specially for beginners

from parse-sdk-js.

lacker avatar lacker commented on July 20, 2024

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.

dplewis avatar dplewis commented on July 20, 2024

Closed via #620

As of 2.0 of this SDK Backbone-style callbacks have been removed.

from parse-sdk-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.