mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-21 11:08:55 +00:00
In comparison to generic page-wise hot reloading, this technique requires using dedicated component within a storybook page but provides greater flexibility e.g. preserving component state across source reloads. Closes: #7975
54 lines
1.2 KiB
QML
54 lines
1.2 KiB
QML
import QtQuick 2.14
|
|
|
|
import Storybook 1.0
|
|
|
|
QtObject {
|
|
id: root
|
|
|
|
property string source
|
|
property bool rethrowErrors: true
|
|
readonly property alias component: d.component
|
|
readonly property alias errors: d.errors // QQmlError
|
|
|
|
onSourceChanged: d.createComponent()
|
|
|
|
readonly property Connections _d: Connections {
|
|
id: d
|
|
|
|
target: SourceWatcher
|
|
|
|
property Component component
|
|
property var errors: null
|
|
|
|
function createComponent() {
|
|
if (component) {
|
|
component.destroy()
|
|
component = null
|
|
}
|
|
|
|
try {
|
|
component = Qt.createQmlObject(root.source,
|
|
this,
|
|
"HotComponentFromSource_dynamicSnippet"
|
|
)
|
|
d.errors = null
|
|
} catch (e) {
|
|
d.errors = e
|
|
|
|
if (root.rethrowErrors)
|
|
throw e
|
|
}
|
|
}
|
|
|
|
function onChanged() {
|
|
CacheCleaner.clearComponentCache()
|
|
createComponent()
|
|
}
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
if (root.source)
|
|
d.createComponent()
|
|
}
|
|
}
|