Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rsvp.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
rsvp.js
Commits
46bce2f6
Commit
46bce2f6
authored
Mar 31, 2013
by
Stefan Penner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RSVP 2.0 related doc fixes
parent
c6b2886d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
21 deletions
+22
-21
README.md
README.md
+22
-21
No files found.
README.md
View file @
46bce2f6
...
...
@@ -27,20 +27,21 @@ section below on TaskJS for more information.
### Basic Usage
```
javascript
var
promise
=
new
Promise
();
var
promise
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
){
// succeed
resolve
(
value
);
// or reject
reject
(
error
);
});
promise
.
then
(
function
(
value
)
{
// success
},
function
(
value
)
{
// 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
rejected again.
...
...
@@ -48,21 +49,21 @@ Here is an example of a simple XHR2 wrapper written using RSVP.js:
```
javascript
var
getJSON
=
function
(
url
)
{
var
promise
=
new
RSVP
.
Promise
(
);
var
client
=
new
XMLHttpRequest
(
);
client
.
open
(
"
GET
"
,
url
)
;
client
.
onreadystatechange
=
handler
;
client
.
responseType
=
"
json
"
;
client
.
setRequestHeader
(
"
Accept
"
,
"
application/json
"
);
client
.
send
();
function
handler
(
)
{
if
(
this
.
readyState
===
this
.
DONE
)
{
if
(
this
.
status
===
200
)
{
promise
.
resolve
(
this
.
response
);
}
else
{
promise
.
reject
(
this
);
}
}
};
var
promise
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
){
var
client
=
new
XMLHttpRequest
();
client
.
open
(
"
GET
"
,
url
);
client
.
onreadystatechange
=
handler
;
client
.
responseType
=
"
json
"
;
client
.
setRequestHeader
(
"
Accept
"
,
"
application/json
"
)
;
client
.
send
(
);
function
handler
()
{
if
(
this
.
readyState
===
this
.
DONE
)
{
if
(
this
.
status
===
200
)
{
resolve
(
this
.
response
);
}
else
{
reject
(
this
);
}
}
}
;
}
)
;
return
promise
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment