-
-
Notifications
You must be signed in to change notification settings - Fork 598
⚡ Release v2.0.1 #624
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
⚡ Release v2.0.1 #624
Changes from 4 commits
d50284b
09310b5
a17fa61
c5d8d56
ea31d09
96bbc72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Upgrading Parse SDK to version 2.0.0 | ||
|
||
With Parse SDK 2.0.0, gone are the backbone style callbacks and Parse.Promises. | ||
|
||
Instead, the Parse SDK 2.0.0 uses native promises in the browser, node and react native that allows for a more standard API. | ||
|
||
Migrating to native Promises should be straightforward, we'll recap the different changes: | ||
|
||
## `.done()` and `.fail()` continuations | ||
|
||
With native promises, `.done` and `.fail` don't exist and are replaces by `.then` and `.catch` | ||
|
||
```js | ||
// before | ||
const query = new Parse.Query(); | ||
query.find() | ||
.done((results) => { | ||
|
||
}) | ||
.fail((error) => { | ||
|
||
}); | ||
|
||
// after | ||
query.find() | ||
.then((results) => { | ||
|
||
}) | ||
.catch((error) => { | ||
|
||
}); | ||
``` | ||
|
||
## `.always()` is replaced by `.finally()` | ||
|
||
```js | ||
// before | ||
const query = new Parse.Query(); | ||
query.find() | ||
.always((result) => { | ||
|
||
}); | ||
|
||
// after | ||
query.find() | ||
.finally((result) => { | ||
|
||
}); | ||
``` | ||
|
||
## `new Parse.Promise()` | ||
|
||
With native promises, the constructor is different, you will need to update to the native constructor which requires moving the code around. | ||
|
||
```js | ||
// before | ||
const promise = new Promise(); | ||
doSomethingAsync((error, success) => { | ||
if (error) { promise.reject(error); } | ||
else { promise.resolve(success); } | ||
}); | ||
return promise; | ||
|
||
// after | ||
return new Promise((resolve, reject) => { | ||
doSomethingAsync((error, success) => { | ||
if (error) { reject(error); } | ||
else { resolve(success); } | ||
}); | ||
}); | ||
``` | ||
|
||
## Static methods | ||
|
||
- `Parse.Promise.as` is replaced by `Promise.resolve` | ||
- `Parse.Promise.error` is replaced by `Promise.reject` | ||
- `Parse.Promise.when` is replaced by `Promise.all` | ||
|
||
:warning: `Promise.all` only takes an array or an iterable promises. | ||
|
||
```js | ||
// before | ||
Parse.Promise.when(promise1, promise2, promise3) | ||
.then((result1, result2, result3) => { | ||
|
||
}); | ||
|
||
// after | ||
Promise.all([promise1, promise2, promise3]) | ||
.then(([result1, result2, result3]) => { | ||
|
||
}); | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,13 @@ | |
* Defines a Cloud Function. | ||
* | ||
* **Available in Cloud Code only.** | ||
* **Starting parse-server 3.0.0, all cloud hooks and functions are asynchronous** | ||
* **All response objects are removed and replaced by promises / async/await based resolution** | ||
* | ||
* @method define | ||
* @name Parse.Cloud.define | ||
* @param {String} name The name of the Cloud Function | ||
* @param {Function} data The Cloud Function to register. This function should take two parameters a {@link Parse.Cloud.FunctionRequest} and a {@link Parse.Cloud.FunctionResponse} | ||
* @param {Function} data The Cloud Function to register. This function can be an async function and should take one parameter a {@link Parse.Cloud.FunctionRequest}. | ||
*/ | ||
|
||
/** | ||
|
@@ -16,19 +18,19 @@ | |
* | ||
* If you want to use afterDelete for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), you should pass the class itself and not the String for arg1. | ||
* ``` | ||
* Parse.Cloud.afterDelete('MyCustomClass', (request) => { | ||
* Parse.Cloud.afterDelete('MyCustomClass', async (request) => { | ||
* // code here | ||
* }) | ||
* | ||
* Parse.Cloud.afterDelete(Parse.User, (request) => { | ||
* Parse.Cloud.afterDelete(Parse.User, async (request) => { | ||
* // code here | ||
* }) | ||
*``` | ||
* | ||
* @method afterDelete | ||
* @name Parse.Cloud.afterDelete | ||
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the after delete function for. This can instead be a String that is the className of the subclass. | ||
* @param {Function} func The function to run after a delete. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}. | ||
* @param {Function} func The function to run after a delete. This function can be async and should take just one parameter, {@link Parse.Cloud.TriggerRequest}. | ||
*/ | ||
|
||
/** | ||
|
@@ -40,19 +42,19 @@ | |
* If you want to use afterSave for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), you should pass the class itself and not the String for arg1. | ||
* | ||
* ``` | ||
* Parse.Cloud.afterSave('MyCustomClass', function(request) { | ||
* Parse.Cloud.afterSave('MyCustomClass', async function(request) { | ||
* // code here | ||
* }) | ||
* | ||
* Parse.Cloud.afterSave(Parse.User, function(request) { | ||
* Parse.Cloud.afterSave(Parse.User, async function(request) { | ||
* // code here | ||
* }) | ||
* ``` | ||
* | ||
* @method afterSave | ||
* @name Parse.Cloud.afterSave | ||
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the after save function for. This can instead be a String that is the className of the subclass. | ||
* @param {Function} func The function to run after a save. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}. | ||
* @param {Function} func The function to run after a save. This function can be an async function and should take just one parameter, {@link Parse.Cloud.TriggerRequest}. | ||
*/ | ||
|
||
/** | ||
|
@@ -62,19 +64,19 @@ | |
* | ||
* If you want to use beforeDelete for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), you should pass the class itself and not the String for arg1. | ||
* ``` | ||
* Parse.Cloud.beforeDelete('MyCustomClass', (request, response) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it remove response in beforeDelete?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In parse-server 3.0 (the the docs update is for parse-server 3.0) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand this leads to a lot of confusion, I'll bring in the CLoud Code docs in parse-server instead. And just add the link here. I'll revert cloud code docs for now :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. goood :) |
||
* Parse.Cloud.beforeDelete('MyCustomClass', (request) => { | ||
* // code here | ||
* }) | ||
* | ||
* Parse.Cloud.beforeDelete(Parse.User, (request, response) => { | ||
* Parse.Cloud.beforeDelete(Parse.User, (request) => { | ||
* // code here | ||
* }) | ||
*``` | ||
* | ||
* @method beforeDelete | ||
* @name Parse.Cloud.beforeDelete | ||
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the before delete function for. This can instead be a String that is the className of the subclass. | ||
* @param {Function} func The function to run before a delete. This function should take two parameters a {@link Parse.Cloud.TriggerRequest} and a {@link Parse.Cloud.BeforeDeleteResponse}. | ||
* @param {Function} func The function to run before a delete. This function can be async and should take one parameter, a {@link Parse.Cloud.TriggerRequest}. | ||
*/ | ||
|
||
/** | ||
|
@@ -86,19 +88,19 @@ | |
* If you want to use beforeSave for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), you should pass the class itself and not the String for arg1. | ||
* | ||
* ``` | ||
* Parse.Cloud.beforeSave('MyCustomClass', (request, response) => { | ||
* Parse.Cloud.beforeSave('MyCustomClass', (request) => { | ||
* // code here | ||
* }) | ||
* | ||
* Parse.Cloud.beforeSave(Parse.User, (request, response) => { | ||
* Parse.Cloud.beforeSave(Parse.User, (request) => { | ||
* // code here | ||
* }) | ||
* ``` | ||
* | ||
* @method beforeSave | ||
* @name Parse.Cloud.beforeSave | ||
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the after save function for. This can instead be a String that is the className of the subclass. | ||
* @param {Function} func The function to run before a save. This function should take two parameters a {@link Parse.Cloud.TriggerRequest} and a {@link Parse.Cloud.BeforeSaveResponse}. | ||
* @param {Function} func The function to run before a save. This function can be async and should take one parameter a {@link Parse.Cloud.TriggerRequest}; | ||
*/ | ||
|
||
/** | ||
|
@@ -135,7 +137,7 @@ | |
* @method job | ||
* @name Parse.Cloud.job | ||
* @param {String} name The name of the Background Job | ||
* @param {Function} func The Background Job to register. This function should take two parameters a {@link Parse.Cloud.JobRequest} and a {@link Parse.Cloud.JobStatus} | ||
* @param {Function} func The Background Job to register. This function can be async should take a single parameters a {@link Parse.Cloud.JobRequest} | ||
* | ||
*/ | ||
|
||
|
@@ -163,31 +165,7 @@ | |
/** | ||
* @typedef Parse.Cloud.JobRequest | ||
* @property {Object} params The params passed to the background job. | ||
*/ | ||
|
||
/** | ||
* @typedef Parse.Cloud.JobStatus | ||
* @property {function} error If error is called, will end the job unsuccessfully with an optional completion message to be stored in the job status. | ||
* @property {function} message If message is called with a string argument, will update the current message to be stored in the job status. | ||
* @property {function} success If success is called, will end the job successfullly with the optional completion message to be stored in the job status. | ||
*/ | ||
|
||
/** | ||
* @typedef Parse.Cloud.BeforeSaveResponse | ||
* @property {function} success If called, will allow the save to happen. If a Parse.Object is passed in, then the passed in object will be saved instead. | ||
* @property {function} error If called, will reject the save. An optional error message may be passed in. | ||
*/ | ||
|
||
/** | ||
* @typedef Parse.Cloud.BeforeDeleteResponse | ||
* @property {function} success If called, will allow the delete to happen. | ||
* @property {function} error If called, will reject the save. An optional error message may be passed in. | ||
*/ | ||
|
||
/** | ||
* @typedef Parse.Cloud.FunctionResponse | ||
* @property {function} success If success is called, will return a successful response with the optional argument to the caller. | ||
* @property {function} error If error is called, will return an error response with an optionally passed message. | ||
*/ | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just curios about this CloudCode. Is it work in browser now? or is your long-team plan?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's in the server, but that's easier to have the whole cloud code API documentation with the rest of the JS SDK, we may move it at a later point if we generate a bigger API docs for parse-server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, i see i just confused :)