diff --git a/bluebird.md b/bluebird.md index cc356e0a4..70b21de4e 100644 --- a/bluebird.md +++ b/bluebird.md @@ -3,43 +3,24 @@ title: bluebird.js layout: default --- -### Creating promises - -```js -var Promise = require("bluebird"); - -new Promise(function (ok, err) { - doStuff(function () { - if (success) - ok(); - else - err(); - }); -}) -``` +See [promise](promise.html). ### Consuming promises ```js promise .then(okFn, errFn) - .spread(okFn, errFn) + .spread(okFn, errFn) #* .catch(errFn) - .catch(TypeError, errFn) - .finally(fn) + .catch(TypeError, errFn) #* + .finally(fn) #* + .map(function (e) { ... }) + .each(function (e) { ... }); ``` ### Handling simultaneous promises -Via Arrays - ```js -var promises = [ - promise1(), promise2(), ... -] - -Promise.all(promises) // succeeds when all succeed - .then(...) Promise.any(promises) // succeeds if one succeeds first .then(...) ``` @@ -57,19 +38,10 @@ Promise.props({ }) ``` -### Turn foreign promises into Bluebird promises - -```js -Promise.resolve($.get('http://google.com')) -.then(...) -``` - ### Consuming arrays ```js getFiles() - .map(function (e) { ... }) - .each(function (e) { ... }); ``` ### Chain of promises diff --git a/promise.md b/promise.md new file mode 100644 index 000000000..b1bbd4286 --- /dev/null +++ b/promise.md @@ -0,0 +1,59 @@ +--- +title: Promises +layout: default +--- + +Based on +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise + +### Creating promises + +```js +new Promise(function (ok, err) { + doStuff(function () { + if (success) + ok(); + else + err(); + }); +}) +``` + +### Consuming promises + +```js +promise + .then(okFn, errFn) + .catch(errFn) +``` + +### Multiple promises + +```js +var promises = [ + promise1(), promise2(), ... +] + +// succeeds when all succeed +Promise.all(promises) + .then(function (values) { + }); + +// succeeds when one finishes first +Promise.race(promises) + .then(function (value) { + }); +``` + +### Converting other promises + +```js +Promise.resolve("reason"); +Promise.resolve(promise); +Promise.resolve(thenable); + +Promise.reject("reason"); + +Promise.resolve($.get('http://google.com')) +.then(...) +``` diff --git a/qunit.md b/qunit.md new file mode 100644 index 000000000..a62f622d2 --- /dev/null +++ b/qunit.md @@ -0,0 +1,28 @@ +--- +title: Qunit +layout: default +--- + + QUnit.module('a'); + QUnit.test('ok', function (t) { ... }); + QUnit.moduleStart(function) + QUnit.moduleEnd(function) + +### Assertions + + t.equal(actual, expected) + t.deepEqual(actual, expected) + t.strictEqual(actual, expected) + t.propEqual(actual, expected) + + t.notEqual + + t.expect(amount) + +### Setup and teardown + + QUnit.begin(function (details) { + }); + + QUnit.done(function (details) { + });