diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-06-29 01:02:07 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-06-29 01:02:07 +0200 |
commit | dd333172e2ade1db6d0af72b4ed44262c2b4d8c7 (patch) | |
tree | 16301a9b938826cf4b78b751907378d96423c5d0 /src/qml/doc | |
parent | 3d266d90cb920375bb856844baea290e52355aad (diff) | |
parent | ffeaac704efc9eb85464d0a401d98e28991ec4d3 (diff) |
Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: I800f39ea59efd6049d3226ec27b8ecb3f6e9ae28
Diffstat (limited to 'src/qml/doc')
-rw-r--r-- | src/qml/doc/src/javascript/resources.qdoc | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/qml/doc/src/javascript/resources.qdoc b/src/qml/doc/src/javascript/resources.qdoc index 34b0610f74..60f97c2007 100644 --- a/src/qml/doc/src/javascript/resources.qdoc +++ b/src/qml/doc/src/javascript/resources.qdoc @@ -26,7 +26,7 @@ ****************************************************************************/ /*! \page qtqml-javascript-resources.html -\title Defining JavaScript Resources In QML +\title Defining JavaScript Resources in QML \brief Description of how JavaScript files may be defined for use in QML The program logic for a QML application may be defined in JavaScript. The @@ -60,7 +60,8 @@ An example of a code-behind implementation resource follows: \code // MyButton.qml import QtQuick 2.0 -import "my_button_impl.js" as Logic // a new instance of this JavaScript resource is loaded for each instance of Button.qml +import "my_button_impl.js" as Logic // A new instance of this JavaScript resource + // is loaded for each instance of Button.qml. Rectangle { id: rect @@ -95,13 +96,18 @@ for maintainability and readability. \section1 Shared JavaScript Resources (Libraries) -Some JavaScript files act more like libraries - they provide a set of helper -functions that take input and compute output, but never manipulate QML -component instances directly. +By default, JavaScript files imported from QML share their context with the QML +component. That means the JavaScript files have access to the same QML objects +and can modify them. As a consequence, each import must have a unique copy of +these files. -As it would be wasteful for each QML component instance to have a unique copy of -these libraries, the JavaScript programmer can indicate a particular file is a -shared library through the use of a pragma, as shown in the following example. +\l {Defining JavaScript Resources in QML#Code-Behind Implementation Resource} +{The previous section} covers stateful imports of JavaScript files. However, +some JavaScript files are stateless and act more like reusable libraries, in +the sense that they provide a set of helper functions that do not require +anything from where they were imported from. You can save significant amounts +of memory and speed up the instantiation of QML components if you mark such +libraries with a special pragma, as shown in the following example. \code // factorial.js @@ -141,7 +147,10 @@ For example: \code // Calculator.qml import QtQuick 2.0 -import "factorial.js" as FactorialCalculator // this JavaScript resource is only ever loaded once by the engine, even if multiple instances of Calculator.qml are created +import "factorial.js" as FactorialCalculator // This JavaScript resource is only + // ever loaded once by the engine, + // even if multiple instances of + // Calculator.qml are created. Text { width: 500 |