EMBER WORKSHOP: RSVP simple
HTML
<script src="http://rsvpjs-builds.s3.amazonaws.com/rsvp-latest.js"></script>
<button id="success">Success using RSVP</button>
<button id="failure">Failure using RSVP</button>
<br>
<button id="successNative">Success using Native</button>
<button id="failureNative">Failure using Native</button>
<br>
<button id="successMix">Success using Mix</button>
<button id="failureMix">Failure using Mix</button>
JavaScript
doSomething()
.then(function() {
console.log('final success');
})
.catch(function() {
console.log('final failure');
});
doSomethingNative()
.then(function() {
console.log('final success');
})
.catch(function() {
console.log('final failure');
});
doSomethingMix()
.then(function() {
console.log('final success');
})
.catch(function() {
console.log('final failure');
});
//================================================================================
function doSomething() {
return new RSVP.Promise(function (fulfill, reject) {
document.getElementById("success").addEventListener("click", function () {
fulfill("Promise fulfilled!");
});
document.getElementById("failure").addEventListener("click", function () {
reject("Promise rejected!");
});
}).then(function(message) {
console.log('doSomething sucess', message)
}).catch(function(error) {
console.log('doSomething catch', error);
return RSVP.Promise.reject('catch doSomething');
});
}
function doSomethingNative() {
return new Promise(function (fulfill, reject) {
document.getElementById("successNative").addEventListener("click", function () {
fulfill("Promise fulfilled!");
});
document.getElementById("failureNative").addEventListener("click", function () {
reject("Promise rejected!");
});
}).then(function(message) {
console.log('doSomething sucess', message)
}).catch(function(error) {
console.log('doSomething catch', error);
return Promise.reject('catch doSomething');
});
}
function doSomethingMix() {
return new Promise(function (fulfill, reject) {
document.getElementById("successMix").addEventListener("click", function () {
fulfill("Promise fulfilled!");
});
document.getElementById("failureMix").addEventListener("click", function () {
...