complete pure call

This commit is contained in:
王劲鹏 2021-05-31 16:00:06 +08:00 committed by osborn
parent 9f721aa1c8
commit 4c5cd39320
12 changed files with 66 additions and 68 deletions

View File

@ -59,15 +59,18 @@ void DoricDemoBridge::navigate(QVariant route) {
name = "SimpleDemo.js";
break;
case 14:
name = "Snake.js";
name = "SliderDemo.js";
break;
case 15:
name = "StorageDemo.js";
name = "Snake.js";
break;
case 16:
name = "SwitchDemo.js";
name = "StorageDemo.js";
break;
case 17:
name = "SwitchDemo.js";
break;
case 18:
name = "TextDemo.js";
break;
}

View File

@ -15,7 +15,7 @@ ApplicationWindow {
ListView {
width: parent.width
model: 18
model: 19
delegate: Rectangle {
Column {
anchors.centerIn: parent
@ -51,12 +51,14 @@ ApplicationWindow {
case 13:
return "SimpleDemo.js"
case 14:
return "Snake.js"
return "SliderDemo.js"
case 15:
return "StorageDemo.js"
return "Snake.js"
case 16:
return "SwitchDemo.js"
return "StorageDemo.js"
case 17:
return "SwitchDemo.js"
case 18:
return "TextDemo.js"
}
}

View File

@ -21,8 +21,9 @@
<file alias="ModularDemo.js">../../../doric-demo/bundle/src/ModularDemo.js</file>
<file alias="NetworkDemo.js">../../../doric-demo/bundle/src/NetworkDemo.js</file>
<file alias="PopoverDemo.js">../../../doric-demo/bundle/src/PopoverDemo.js</file>
<file alias="SimpleDemo.js">../../../doric-demo/bundle/src/SimpleDemo.js</file>
<file alias="ScrollerDemo.js">../../../doric-demo/bundle/src/ScrollerDemo.js</file>
<file alias="SimpleDemo.js">../../../doric-demo/bundle/src/SimpleDemo.js</file>
<file alias="SliderDemo.js">../../../doric-demo/bundle/src/SliderDemo.js</file>
<file alias="Snake.js">../../../doric-demo/bundle/src/Snake.js</file>
<file alias="StorageDemo.js">../../../doric-demo/bundle/src/StorageDemo.js</file>
<file alias="SwitchDemo.js">../../../doric-demo/bundle/src/SwitchDemo.js</file>

View File

@ -1,13 +1,31 @@
#include "DoricAsyncResult.h"
#include <QWaitCondition>
DoricAsyncResult::DoricAsyncResult() {}
void DoricAsyncResult::setResult(QString result) { this->result = result; }
void DoricAsyncResult::setResult(QString result) {
this->result = result;
this->resultCallback();
}
void DoricAsyncResult::setError(QString exception) { this->result = exception; }
bool DoricAsyncResult::hasResult() { return !(result == EMPTY); }
bool DoricAsyncResult::hasResult() { return !(result.isEmpty()); }
QJSValue DoricAsyncResult::getResult() { return this->result; }
QString DoricAsyncResult::getResult() { return this->result; }
DoricSettableFuture *DoricAsyncResult::synchronous() { return NULL; }
QString DoricAsyncResult::waitUntilResult() {
if (hasResult()) {
return this->result;
}
QMutex mutex;
QWaitCondition condition;
this->resultCallback = [&condition]() { condition.wakeAll(); };
mutex.lock();
condition.wait(&mutex);
mutex.unlock();
return this->result;
}

View File

@ -1,17 +1,13 @@
#ifndef ASYNCRESULT_H
#define ASYNCRESULT_H
#include <QJSValue>
#include <QString>
#include "DoricExport.h"
#include "DoricSettableFuture.h"
static QString EMPTY("");
class DORIC_EXPORT DoricAsyncResult {
private:
QString result = EMPTY;
QString result;
public:
std::function<void()> resultCallback;
@ -26,9 +22,9 @@ public:
bool hasResult();
QJSValue getResult();
QString getResult();
DoricSettableFuture *synchronous();
QString waitUntilResult();
};
#endif // ASYNCRESULT_H

View File

@ -1,17 +0,0 @@
#include <QDebug>
#include "DoricSettableFuture.h"
void DoricSettableFuture::set(QJSValue result) {
if (mReadyLatch == NULL) {
qDebug() << "Result has already been set!";
return;
}
mResult = result;
delete mReadyLatch;
}
QJSValue DoricSettableFuture::get() {
mReadyLatch->lock();
return mResult;
}

View File

@ -1,21 +0,0 @@
#ifndef SETTABLE_FUTURE_H
#define SETTABLE_FUTURE_H
#include <QJSValue>
#include "DoricExport.h"
#include "utils/DoricCountDownLatch.h"
class DORIC_EXPORT DoricSettableFuture {
private:
QJSValue mResult;
DoricCountDownLatch *mReadyLatch = new DoricCountDownLatch();
public:
void set(QJSValue result);
QJSValue get();
};
#endif // SETTABLE_FUTURE_H

View File

@ -26,7 +26,6 @@ SOURCES += \
DoricPanel.cpp \
DoricRegistry.cpp \
async/DoricAsyncResult.cpp \
async/DoricSettableFuture.cpp \
engine/DoricBridgeExtension.cpp \
engine/DoricJSEngine.cpp \
engine/DoricNativeEmpty.cpp \
@ -105,7 +104,6 @@ HEADERS += \
DoricRegistry.h \
async/DoricAsyncCall.h \
async/DoricAsyncResult.h \
async/DoricSettableFuture.h \
engine/DoricBridgeExtension.h \
engine/DoricInterfaceJSE.h \
engine/DoricJSEngine.h \

View File

@ -1,6 +1,8 @@
import QtQuick 2.12
import QtQuick.Controls 2.5
import "util.mjs" as Util
SwipeView {
property var wrapper

View File

@ -232,8 +232,8 @@ DoricViewNode::pureCallJSResponse(QString funcId, QVariantList args) {
foreach (const QVariant &arg, args)
nArgs.append(arg);
return getContext()->callEntity(DoricConstant::DORIC_CONTEXT_INVOKE_PURE,
nArgs);
return getContext()->getDriver()->invokeDoricMethod(
DoricConstant::DORIC_CONTEXT_INVOKE_PURE, nArgs);
}
void DoricViewNode::onClick() {

View File

@ -32,15 +32,33 @@ void DoricSliderNode::blendSubNode(QJsonValue subProperties) {
}
}
void DoricSliderNode::blend(QJsonValue jsValue) {}
void DoricSliderNode::blend(QQuickItem *view, QString name, QJsonValue prop) {}
void DoricSliderNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
if (name == "itemCount") {
this->itemCount = prop.toInt();
} else if (name == "renderPage") {
if (prop.toString() != this->renderPageFuncId) {
this->childNodes.clear();
this->renderPageFuncId = prop.toString();
}
} else if (name == "batchCount") {
this->batchCount = prop.toInt();
} else if (name == "onPageSlided") {
this->onPageSelectedFuncId = prop.toString();
} else if (name == "loop") {
this->loop = prop.toBool();
} else {
DoricViewNode::blend(view, name, prop);
}
}
void DoricSliderNode::afterBlended(QJsonValue prop) {
if (this->childNodes.length() != this->itemCount) {
QVariantList args;
args.append(this->childNodes.length());
args.append(this->itemCount);
this->pureCallJSResponse("renderBunchedItems", args);
std::shared_ptr<DoricAsyncResult> asyncResult =
this->pureCallJSResponse("renderBunchedItems", args);
QString result = asyncResult->waitUntilResult();
qDebug() << result;
}
}

View File

@ -25,8 +25,6 @@ public:
virtual void blendSubNode(QJsonValue subProperties) override;
virtual void blend(QJsonValue jsValue) override;
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
virtual void afterBlended(QJsonValue prop) override;