Commit 46bce2f6 authored by Stefan Penner's avatar Stefan Penner

RSVP 2.0 related doc fixes

parent c6b2886d
...@@ -27,20 +27,21 @@ section below on TaskJS for more information. ...@@ -27,20 +27,21 @@ section below on TaskJS for more information.
### Basic Usage ### Basic Usage
```javascript ```javascript
var promise = new Promise(); var promise = new RSVP.Promise(function(resolve, reject){
// succeed
resolve(value);
// or reject
reject(error);
});
promise.then(function(value) { promise.then(function(value) {
// success // success
}, function(value) { }, function(value) {
// failure // failure
}); });
// later...
promise.resolve(value) // triggers first callback
promise.reject(error) // triggers second callback
``` ```
Once a promise has been resolved or rejected, it cannot be resolved or Once a promise has been resolved or rejected, it cannot be resolved or
rejected again. rejected again.
...@@ -48,8 +49,7 @@ Here is an example of a simple XHR2 wrapper written using RSVP.js: ...@@ -48,8 +49,7 @@ Here is an example of a simple XHR2 wrapper written using RSVP.js:
```javascript ```javascript
var getJSON = function(url) { var getJSON = function(url) {
var promise = new RSVP.Promise(); var promise = new RSVP.Promise(function(resolve, reject){
var client = new XMLHttpRequest(); var client = new XMLHttpRequest();
client.open("GET", url); client.open("GET", url);
client.onreadystatechange = handler; client.onreadystatechange = handler;
...@@ -59,10 +59,11 @@ var getJSON = function(url) { ...@@ -59,10 +59,11 @@ var getJSON = function(url) {
function handler() { function handler() {
if (this.readyState === this.DONE) { if (this.readyState === this.DONE) {
if (this.status === 200) { promise.resolve(this.response); } if (this.status === 200) { resolve(this.response); }
else { promise.reject(this); } else { reject(this); }
} }
}; };
});
return promise; return promise;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment