|
| 1 | +# Upgrading Parse SDK to version 2.0.0 |
| 2 | + |
| 3 | +With Parse SDK 2.0.0, gone are the backbone style callbacks and Parse.Promises. |
| 4 | + |
| 5 | +Instead, the Parse SDK 2.0.0 uses native promises in the browser, node and react native that allows for a more standard API. |
| 6 | + |
| 7 | +Migrating to native Promises should be straightforward, we'll recap the different changes: |
| 8 | + |
| 9 | +## `.done()` and `.fail()` continuations |
| 10 | + |
| 11 | +With native promises, `.done` and `.fail` don't exist and are replaces by `.then` and `.catch` |
| 12 | + |
| 13 | +```js |
| 14 | +// before |
| 15 | +const query = new Parse.Query(); |
| 16 | +query.find() |
| 17 | +.done((results) => { |
| 18 | + |
| 19 | +}) |
| 20 | +.fail((error) => { |
| 21 | + |
| 22 | +}); |
| 23 | + |
| 24 | +// after |
| 25 | +query.find() |
| 26 | +.then((results) => { |
| 27 | + |
| 28 | +}) |
| 29 | +.catch((error) => { |
| 30 | + |
| 31 | +}); |
| 32 | +``` |
| 33 | + |
| 34 | +## `.always()` is replaced by `.finally()` |
| 35 | + |
| 36 | +```js |
| 37 | +// before |
| 38 | +const query = new Parse.Query(); |
| 39 | +query.find() |
| 40 | +.always((result) => { |
| 41 | + |
| 42 | +}); |
| 43 | + |
| 44 | +// after |
| 45 | +query.find() |
| 46 | +.finally((result) => { |
| 47 | + |
| 48 | +}); |
| 49 | +``` |
| 50 | + |
| 51 | +## `new Parse.Promise()` |
| 52 | + |
| 53 | +With native promises, the constructor is different, you will need to update to the native constructor which requires moving the code around. |
| 54 | + |
| 55 | +```js |
| 56 | +// before |
| 57 | +const promise = new Promise(); |
| 58 | +doSomethingAsync((error, success) => { |
| 59 | + if (error) { promise.reject(error); } |
| 60 | + else { promise.resolve(success); } |
| 61 | +}); |
| 62 | +return promise; |
| 63 | + |
| 64 | +// after |
| 65 | +return new Promise((resolve, reject) => { |
| 66 | + doSomethingAsync((error, success) => { |
| 67 | + if (error) { reject(error); } |
| 68 | + else { resolve(success); } |
| 69 | + }); |
| 70 | +}); |
| 71 | +``` |
| 72 | + |
| 73 | +## Static methods |
| 74 | + |
| 75 | +- `Parse.Promise.as` is replaced by `Promise.resolve` |
| 76 | +- `Parse.Promise.error` is replaced by `Promise.reject` |
| 77 | +- `Parse.Promise.when` is replaced by `Promise.all` |
0 commit comments