Skip to content

Commit

Permalink
Extra test case and document about "Minimal Installation"
Browse files Browse the repository at this point in the history
  • Loading branch information
benlau committed Mar 29, 2018
1 parent d81f812 commit 6516178
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ Usage

```qml
import "./promise.js" as Q
....
/// Q.promise is the creator function of promise. It is equivalent to "new Promise()" in modern browser
var promise = new Q.Promise(function(resolve,reject) {
....
});
```

Reference: [Q.promise()](#qpromise)
Expand Down Expand Up @@ -261,13 +269,19 @@ However, you may still pass a signal object to resolve()/reject(). In this case,

But it don't support to resolve by the result of Qt.binding(). It will just throw exception. In this case, you should use a QML Promise and pass it to resolveWhen property.


Remarks: Q.promise(executor) is equivalent to `new Q.Promise(executor)`.

*API*

```
Promise(executor)
Promise.then = function(onFulfilled,onRejected) { ... }
Promise.resolve = function(result) { ... }
Promise.reject = function(reason) { ... }
Q.Promise(executor)
Q.Promise.prototype.then = function(onFulfilled,onRejected) { ... }
Q.Promise.resolve = function(result) { ... }
Q.Promise.reject = function(reason) { ... }
Q.Promise.all = function(promises) { }
Q.Promise.allSettled = function(promises) { }
```

Instruction of using then/resolve/reject: [Promise](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Promise)
Expand Down
4 changes: 4 additions & 0 deletions qml/QuickPromise/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,7 @@ function allSettled(promises) {

return combinator._combined;
}

Promise.all = all;
Promise.resolve = resolve;
Promise.reject = reject;
40 changes: 40 additions & 0 deletions tests/unittests/tst_promisejs_minimal.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import QtQuick 2.0
import QtTest 1.0
import "qrc:///QuickPromise/promise.js" as Q


TestCase {
name : "PromiseJS_Minimal"

function tick() {
wait(0);
wait(0);
wait(0);
}

function test_constructor() {
var callbackResult = {}

var promise = new Q.Promise(function(resolve, reject) {
resolve("ready") ;
});

tick();

compare(callbackResult.result, "ready");
}

function test_resolve() {
var promise = Q.Promise.resolve("done");
var callbackResult = {}
promise.then(function(result) {
callbackResult.result = result;
});

tick();

compare(callbackResult.result, "done");
}


}
3 changes: 2 additions & 1 deletion tests/unittests/unittests.pro
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ DISTFILES += \
tst_timer.qml \
tst_promisejs_examples.qml \
tst_promisejs_executor.qml \
tst_promisejs_then.qml
tst_promisejs_then.qml \
tst_promisejs_minimal.qml

0 comments on commit 6516178

Please sign in to comment.