From 4cc0ab1eef37f0c5cc4cad47e6bdb36caa5f819d Mon Sep 17 00:00:00 2001 From: Atul R Date: Wed, 11 Sep 2019 22:30:10 +0200 Subject: [PATCH] Adds bootstrap example --- src/demo.ts | 1 + src/index.ts | 2 ++ src/lib/core/Style/StyleSheet.ts | 6 ++---- src/lib/core/bootstrap.ts | 26 ++++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 src/lib/core/bootstrap.ts diff --git a/src/demo.ts b/src/demo.ts index aa79bd563..6d548407a 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -52,6 +52,7 @@ button.addEventListener("clicked", () => { if (rootView.layout) { (rootView.layout as FlexLayout).removeWidget(dial); } + label.setInlineStyle("color:blue;"); }); const nodeguiLogo = new QIcon( diff --git a/src/index.ts b/src/index.ts index 2dba519f1..7acd8a56f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ +// bootstrap +import "./lib/core/bootstrap"; // Enums: export * from "./lib/QtEnums"; // Gui: diff --git a/src/lib/core/Style/StyleSheet.ts b/src/lib/core/Style/StyleSheet.ts index 17ee60168..af070849e 100644 --- a/src/lib/core/Style/StyleSheet.ts +++ b/src/lib/core/Style/StyleSheet.ts @@ -19,7 +19,7 @@ export const prepareInlineStyleSheet = async ( rawStyle: string ) => { const inlineStyle = await StyleSheet.create(rawStyle); - // Make sure to not calculate ObjectName is the same pass of event loop as other props (incase of react) since the order will matter in that case + // Make sure to not calculate ObjectName in the same pass of event loop as other props (incase of react) since the order will matter in that case // So doing it in multiple passes of event loop allows objectName to be set before using it. The above await solves it. let cssId = widget.objectName(); if (!cssId) { @@ -38,7 +38,5 @@ export const applyStyleSheet = async ( styleSheet: string ) => { widget.native.setStyleSheet(styleSheet); - setTimeout(() => { - widget.layout ? widget.layout.update() : widget.update(); - }, 20); + widget.layout ? widget.layout.update() : widget.update(); }; diff --git a/src/lib/core/bootstrap.ts b/src/lib/core/bootstrap.ts new file mode 100644 index 000000000..6ce6a9637 --- /dev/null +++ b/src/lib/core/bootstrap.ts @@ -0,0 +1,26 @@ +/* + From: https://github.com/yue/yode/blob/master/src/bootstrap.js + setImmediate and process.nextTick makes use of uv_check and uv_prepare to + run the callbacks, however since we only run uv loop on requests, the + callbacks wouldn't be called until something else activated the uv loop, + which would delay the callbacks for arbitrary long time. So we should + initiatively activate the uv loop once setImmediate and process.nextTick is + called. + This is required inorder to make the timers work nicely due to merger of event loops +*/ +function wrapWithActivateUvLoop(func: any) { + return function() { + (process as any).activateUvLoop(); + //@ts-ignore + return func.apply(this, arguments); + }; +} + +const main = () => { + process.nextTick = wrapWithActivateUvLoop(process.nextTick); + global.setImmediate = wrapWithActivateUvLoop(global.setImmediate); + global.setTimeout = wrapWithActivateUvLoop(global.setTimeout); + global.setInterval = wrapWithActivateUvLoop(global.setInterval); +}; + +main();