@lynx-js/lynx-runtime 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +354 -2
- package/dist/bts/data.d.ts +1 -0
- package/dist/bts/data.js +28 -0
- package/dist/bts/events.d.ts +1 -0
- package/dist/bts/events.js +57 -0
- package/dist/bts/scope.d.ts +1 -0
- package/dist/bts/scope.js +129 -0
- package/dist/bts/services.d.ts +1 -0
- package/dist/bts/services.js +34 -0
- package/dist/bts.d.ts +14 -0
- package/dist/bts.js +30 -0
- package/dist/common/host-types.d.ts +1 -0
- package/dist/common/host-types.js +1 -0
- package/dist/common/messages.d.ts +1 -0
- package/dist/common/messages.js +69 -0
- package/dist/common/performance.d.ts +1 -0
- package/dist/common/performance.js +26 -0
- package/dist/common/protocol.d.ts +20 -0
- package/dist/common/protocol.js +53 -0
- package/dist/common/types.d.ts +203 -0
- package/dist/common/types.js +1 -0
- package/dist/iife/bts.js +1 -0
- package/dist/iife/mts.js +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +1 -0
- package/dist/mts/data.d.ts +71 -0
- package/dist/mts/data.js +46 -0
- package/dist/mts/flush.d.ts +11 -0
- package/dist/mts/flush.js +16 -0
- package/dist/mts/host.d.ts +35 -0
- package/dist/mts/host.js +124 -0
- package/dist/mts/services.d.ts +21 -0
- package/dist/mts/services.js +46 -0
- package/dist/mts.d.ts +5 -0
- package/dist/mts.js +4 -0
- package/package.json +57 -3
- package/skills/lynx-runtime/SKILL.md +67 -0
- package/src/bts/data.ts +94 -0
- package/src/bts/events.ts +100 -0
- package/src/bts/scope.ts +279 -0
- package/src/bts/services.ts +88 -0
- package/src/bts.ts +110 -0
- package/src/common/host-types.ts +161 -0
- package/src/common/messages.ts +129 -0
- package/src/common/performance.ts +65 -0
- package/src/common/protocol.ts +98 -0
- package/src/common/types.ts +259 -0
- package/src/index.ts +35 -0
- package/src/mts/data.ts +200 -0
- package/src/mts/flush.ts +50 -0
- package/src/mts/host.ts +297 -0
- package/src/mts/services.ts +102 -0
- package/src/mts.ts +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,355 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@lynx-js/lynx-runtime`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DSL-neutral Lynx host runtime primitives for main thread (`@lynx-js/lynx-runtime/mts`) and background thread (`@lynx-js/lynx-runtime/bts`).
|
|
4
|
+
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> **Preview (`0.0.x`):** `@lynx-js/lynx-runtime` is currently released as an early preview ahead of formal RFC stabilization. Public APIs and behavior are not yet guaranteed to be stable and may change in `0.0.x` / `0.x` releases.
|
|
7
|
+
|
|
8
|
+
## Find a starting point
|
|
9
|
+
|
|
10
|
+
Use this package when implementing a DSL's page/host integration. The DSL still
|
|
11
|
+
owns rendering, mutable application state, entry replacement, and message protocols.
|
|
12
|
+
|
|
13
|
+
| Task | Start here |
|
|
14
|
+
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
15
|
+
| Register MTS inputs and submit updates | [MTS input ownership](#mts-input-ownership), [flush](#page-level-flush-flushelementtree) |
|
|
16
|
+
| Keep BTS asynchronous work bound to a page | [BTS capability ownership](#bts-capability-ownership) |
|
|
17
|
+
| Send a message and observe a reply | [Peer messages](#peer-messages) |
|
|
18
|
+
| Retire an entry without destroying the page | [Registration lifetime](#registration-lifetime) |
|
|
19
|
+
| Read initial data or GlobalProps | [Input baseline](#mts-input-ownership), [GlobalProps ownership](#globalprops-across-mts-and-bts) |
|
|
20
|
+
| Install synchronous data hooks or raw event handling | [Data hooks](#native-data-processing--host-updates), [raw BTS events](#raw-bts-events) |
|
|
21
|
+
| Inline into a build-free `.lynxml` document | [Build-free `.lynxml` usage (IIFE)](#build-free-lynxml-usage-iife) |
|
|
22
|
+
|
|
23
|
+
For a runnable Element PAPI example built with `@lynx-js/lynx-runtime/mts` and
|
|
24
|
+
`@lynx-js/lynx-runtime/bts`, see `examples/vanilla` in the `lynx-stack` repository.
|
|
25
|
+
|
|
26
|
+
## Contract at a glance
|
|
27
|
+
|
|
28
|
+
| API | When and where | Ownership and return meaning |
|
|
29
|
+
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
30
|
+
| `bindPage()` | BTS synchronous bootstrap | Captures the current App instance; reuse the handle in asynchronous work. Rebinding the same App does not create a fresh lifetime. |
|
|
31
|
+
| `getInitData()` | Initialize MTS during bootstrap before the first input; BTS capture starts at `bindPage()` | Copies plain records/arrays from the initial or reload baseline; incremental updates do not accumulate here. Opaque values remain shared. |
|
|
32
|
+
| `getGlobalProps()` | MTS or BTS bound handle (`bindPage()` tracks updates from bootstrap) | Borrows the host or bound page's current `GlobalProps` without copying (defaults to `{}`). Neither may be mutated, including nested values. |
|
|
33
|
+
| `onRenderPage` / `onUpdateData` / `onReload` | MTS listeners register before the first input; BTS uses the bound handle for update/reload | Read-only notifications, not a state store. No replay of inputs missed before registration. |
|
|
34
|
+
| `page.onGlobalEvent(name, listener)` | BTS bound handle, while page and `GlobalEventEmitter` are available | Subscribes to the bound page's `GlobalEventEmitter` (`sendGlobalEvent` / exposure / keyboard), sharing one host listener per event name until teardown. |
|
|
35
|
+
| `sendMessage` / `onMessage` | Same-page peer thread; receiver must already be installed | Sending returns `void`, not a receipt. No startup buffer, RPC, or cross-type ordering guarantee. The DSL owns payload validation and completion replies. |
|
|
36
|
+
| `flushElementTree(options?)` | MTS, after applying an update | Submits the page root, not a List subtree. Preserve the input's options even for an empty update. Returning is not layout/paint completion. |
|
|
37
|
+
| `setDataProcessor` / `setPageDataGetter` / `page.setEventHandler` | Install on the owning thread while alive | Single owner, latest registration wins. Disposing the current owner restores the default, not the previous owner. Host calls are synchronous. |
|
|
38
|
+
| `onDestroy` / `isDestroyed` | Host page lifetime | Does not replace entry/component cleanup. Disposers are idempotent. On older MTS hosts, `false` means destruction has not been observed. |
|
|
39
|
+
|
|
40
|
+
After observed destruction begins, registration, sending, and flushing throw;
|
|
41
|
+
captured initial data/GlobalProps remain readable and disposers remain callable.
|
|
42
|
+
See the linked sections below for per-API activation and compatibility details.
|
|
43
|
+
|
|
44
|
+
## Package and host versions
|
|
45
|
+
|
|
46
|
+
Match this README and the exported declarations to the installed
|
|
47
|
+
`@lynx-js/lynx-runtime` version. Also check the actual Native SDK or
|
|
48
|
+
`@lynx-js/web-core` version: updating the JavaScript package does not add host
|
|
49
|
+
capabilities. The compatibility boundary is:
|
|
50
|
+
|
|
51
|
+
| Host capability | Native | Web |
|
|
52
|
+
| ------------------------------------ | ------------------------------------------------------------------------------- | ----------------------------------------------------- |
|
|
53
|
+
| BTS page destruction | Lynx SDK 2.14+ | Supported by the BTS host |
|
|
54
|
+
| MTS destruction & live `GlobalProps` | Lynx SDK 3.4+ (`onDestroy`); SDK 2.14+ (`GlobalProps`) | `@lynx-js/web-core` 0.26.9+ (`lynx.getNative()`) |
|
|
55
|
+
| MTS without `lynx.getNative()` | SDK 2.14–3.3: `onDestroy` returns a no-op disposer; `isDestroyed()` stays false | Earlier hosts without `getNative()` use same fallback |
|
|
56
|
+
|
|
57
|
+
These boundaries describe supported paths and fallbacks, not a device-validation
|
|
58
|
+
matrix. Peer messaging still requires the corresponding host ContextProxy.
|
|
59
|
+
|
|
60
|
+
## Subpath Exports
|
|
61
|
+
|
|
62
|
+
- `@lynx-js/lynx-runtime`: Shared TypeScript types only (`BTSPageRuntime`, `BTSEventHandler`, `CreatedPipelineOptions`, `CreatePipelineOptions`, `LynxSystemInfo`, `MTSFlushContext`, `MTSFlushOptions`, `MTSReloadOptions`, `MTSRenderOptions`, `MTSUpdateOptions`, `BTSUpdateOptions`, `BTSReloadOptions`, `PipelineOptions`, `Unsubscribe`). The package declares `"sideEffects": false`, and runtime entrypoints are imported from `/mts` or `/bts` with zero module-evaluation side effects so bundlers can tree-shake unused imports cleanly. In dual-thread shared files, import types from `@lynx-js/lynx-runtime` and guard runtime calls to `/mts` or `/bts` behind compile-time thread constants (such as `__LEPUS__` / `__JS__`) so dead-code elimination removes cross-thread references before module-graph resolution.
|
|
63
|
+
- `@lynx-js/lynx-runtime/mts`: Main-thread (Lepus) host lifecycle, data flow, single-owner hooks, peer communication, page-level flush and host services (`isDestroyed`, `getInitData`, `getGlobalProps`, `getSystemInfo`, `onRenderPage`, `onUpdateData`, `onReload`, `onGlobalPropsChanged`, `setDataProcessor`, `setPageDataGetter`, `sendMessage`, `onMessage`, `flushElementTree`, `createPipeline`, `markTiming`, `onDestroy`).
|
|
64
|
+
- `@lynx-js/lynx-runtime/bts`: Background-thread (JS) page binding entrypoint (`bindPage(): BTSPageRuntime`). All BTS page capabilities (`isDestroyed`, `getId`, `getInitData`, `getGlobalProps`, `getSystemInfo`, `onUpdateData`, `onGlobalPropsChanged`, `onReload`, `onConfigChanged`, `onEnterForeground`, `onEnterBackground`, `onGlobalEvent`, `setEventHandler`, `sendMessage`, `onMessage`, `createPipeline`, `markTiming`, `onDestroy`) are accessed on the bound `BTSPageRuntime` handle, ensuring deterministic page ownership across synchronous and asynchronous work.
|
|
65
|
+
- `@lynx-js/lynx-runtime/iife/mts` & `@lynx-js/lynx-runtime/iife/bts`: Prebuilt, minified, self-contained ES2017 (matching Rspeedy's default syntax target) classic IIFE scripts for build-free `.lynxml` documents. Inline `/iife/mts` at the top of `<script thread="main">` and `/iife/bts` at the top of `<script thread="background">`; each declares a script-scoped `var LynxRuntime` binding with the corresponding thread's exports without triggering CommonJS module wrapper detection (`module`/`exports`) or leaking across cards in shared BTS contexts.
|
|
66
|
+
- `@lynx-js/lynx-runtime/skill`: Version-matched agent skill (`skills/lynx-runtime/SKILL.md`) covering ESM and `.lynxml` usage patterns, classic-script pitfalls, and `node:vm` testing notes.
|
|
67
|
+
|
|
68
|
+
## Build-free `.lynxml` usage (IIFE)
|
|
69
|
+
|
|
70
|
+
Build-free `.lynxml` documents have no bundler, ESM `import`, or `<script src>`. Inline the verbatim contents of `@lynx-js/lynx-runtime/iife/mts` (`dist/iife/mts.js`) at the top of `<script thread="main">` and `@lynx-js/lynx-runtime/iife/bts` (`dist/iife/bts.js`) at the top of `<script thread="background">` (after any `"use strict";` directive prologue, before executable code) instead of loading `@lynx-js/lynx-runtime` via blocking `lynx.fetchBundle(...).wait(...)`.
|
|
71
|
+
|
|
72
|
+
For quick-start `.lynxml` usage patterns, classic-script naming notes, and `node:vm` testing setup, see `skills/lynx-runtime/SKILL.md` (`@lynx-js/lynx-runtime/skill`).
|
|
73
|
+
|
|
74
|
+
## MTS input ownership
|
|
75
|
+
|
|
76
|
+
Importing `@lynx-js/lynx-runtime/mts` has no module-evaluation side effects, and
|
|
77
|
+
pure query/performance helpers (`isDestroyed`, `getSystemInfo`, `createPipeline`,
|
|
78
|
+
`markTiming`) do not install host input bindings.
|
|
79
|
+
|
|
80
|
+
Calling any MTS page capability (`onRenderPage`, `onUpdateData`, `onReload`,
|
|
81
|
+
`onGlobalPropsChanged`, `getInitData`, `getGlobalProps`, `setDataProcessor`,
|
|
82
|
+
`setPageDataGetter`, `flushElementTree`, `sendMessage`, `onMessage`, `onDestroy`)
|
|
83
|
+
initializes the MTS host bindings once for that context:
|
|
84
|
+
|
|
85
|
+
- Installs Engine listeners (`__RenderPage`, `__UpdatePage`, `__UpdateGlobalProps`)
|
|
86
|
+
when `lynx.getEngine()` is available, plus `globalThis` input handlers and safe
|
|
87
|
+
defaults (`renderPage`, `updatePage`, `updateGlobalProps`, `processData`,
|
|
88
|
+
`getPageData`, `removeComponents`) so C++ `GetAndCall` (`try_call = false`)
|
|
89
|
+
entrypoints never fail on unused channels (for example when the client updates
|
|
90
|
+
`GlobalProps` on a page that has no `onGlobalPropsChanged` subscriber).
|
|
91
|
+
- Binds MTS destruction (`__DestroyLifetime`) when available, and claims
|
|
92
|
+
`processData` / `getPageData` as single-owner slots via `setDataProcessor` /
|
|
93
|
+
`setPageDataGetter`.
|
|
94
|
+
|
|
95
|
+
Initialize MTS capabilities synchronously during startup before the host delivers
|
|
96
|
+
its first input, and do not mix raw `globalThis.renderPage` / `updatePage` /
|
|
97
|
+
`updateGlobalProps` assignments with `@lynx-js/lynx-runtime/mts` on the same page.
|
|
98
|
+
|
|
99
|
+
Runtime captures first-screen and reload inputs before notifying subscribers,
|
|
100
|
+
even if no subscriber exists or all subscribers have unsubscribed. `getInitData()`
|
|
101
|
+
returns a recursively detached copy of that round's initial baseline, independently
|
|
102
|
+
of later DSL state changes (unlike ReactLynx's internal `lynx.__initData`, which
|
|
103
|
+
shallow-merges reload data onto prior runtime state via `Object.assign`, Runtime's
|
|
104
|
+
`getInitData()` replaces prior dynamic keys on `onReload`):
|
|
105
|
+
|
|
106
|
+
- **MTS `getInitData()`**: reflects the processed `TemplateData` delivered to
|
|
107
|
+
`renderPage` (first screen) or `updatePage(..., { reloadTemplate: true })`
|
|
108
|
+
(`onReload`).
|
|
109
|
+
- **BTS `page.getInitData()`**: overlays the current round's processed initial or
|
|
110
|
+
`onReload` `TemplateData` onto the template's static `_params.initData`
|
|
111
|
+
(`encoded_data` synced via `__SetLepusInitData`, or `{}` when unused), keeping
|
|
112
|
+
static template keys intact across `onReload` while replacing prior dynamic keys.
|
|
113
|
+
|
|
114
|
+
The copied records and arrays can be mutated without modifying Runtime snapshots;
|
|
115
|
+
opaque objects retain their identity. Unsubscribing removes the consumer's listener
|
|
116
|
+
while keeping host input capture active until destruction. Activating Runtime after
|
|
117
|
+
inputs have already been delivered cannot recover those earlier inputs.
|
|
118
|
+
|
|
119
|
+
MTS destruction uses `lynx.getNative()` (**Lynx SDK 3.4+** on Native and Web) for
|
|
120
|
+
host destruction notifications (`__DestroyLifetime`). Runtime clears its input
|
|
121
|
+
subscribers and resets single-owner hooks while ignoring any late host inputs; the
|
|
122
|
+
DSL retains ownership of its resource cleanup. On **Lynx SDK 2.14–3.3** or earlier
|
|
123
|
+
`web-core` without `lynx.getNative()`, `mts.onDestroy()` safely degrades to an
|
|
124
|
+
idempotent no-op disposer and relies on whole-page context teardown (whereas BTS
|
|
125
|
+
`page.onDestroy()` is supported across **Lynx SDK 2.14+** and Web).
|
|
126
|
+
|
|
127
|
+
## BTS capability ownership
|
|
128
|
+
|
|
129
|
+
`bindPage()` captures initial data and `GlobalProps`, and tracks reload,
|
|
130
|
+
`GlobalProps` updates, and destruction on the current `App` instance. Call
|
|
131
|
+
`bindPage()` synchronously during page bootstrap and retain the returned
|
|
132
|
+
`BTSPageRuntime` handle for all subsequent asynchronous work on that page.
|
|
133
|
+
|
|
134
|
+
Other BTS notifications (`onUpdateData`, `onConfigChanged`, `onEnterForeground`,
|
|
135
|
+
`onEnterBackground`), `onGlobalEvent`, `onMessage`, and `setEventHandler` attach
|
|
136
|
+
lazily on first use.
|
|
137
|
+
|
|
138
|
+
The bound handle remains readable throughout any pre-existing host destroy handler
|
|
139
|
+
and all Runtime `onDestroy` callbacks, even after the host detaches the page.
|
|
140
|
+
Runtime disables raw event handlers and detaches `GlobalEventEmitter` /
|
|
141
|
+
`CoreContext` listeners when destruction starts, and clears all lifecycle
|
|
142
|
+
listeners in `finally`.
|
|
143
|
+
|
|
144
|
+
## `GlobalProps` across MTS and BTS
|
|
145
|
+
|
|
146
|
+
Both threads expose `getGlobalProps<T>(): Readonly<T>` (defaulting to `{}` when
|
|
147
|
+
unset) and `onGlobalPropsChanged<T>()`, borrowing the current `GlobalProps`
|
|
148
|
+
reference without deep-copying:
|
|
149
|
+
|
|
150
|
+
- **MTS (single-page context)**: `getGlobalProps()` and `onGlobalPropsChanged()`
|
|
151
|
+
borrow the live host `lynx.__globalProps` object directly (updated by the host
|
|
152
|
+
before dispatching `__UpdateGlobalProps` / `updateGlobalProps`, and capturing the
|
|
153
|
+
final reference once destruction starts). `onGlobalPropsChanged` also forwards
|
|
154
|
+
optional `MTSFlushContext` (`options`) when provided by the host.
|
|
155
|
+
- **BTS (multi-page shared context)**: `page.getGlobalProps()` and
|
|
156
|
+
`page.onGlobalPropsChanged()` borrow the bound page's current `GlobalProps`
|
|
157
|
+
reference without deep-copying (captured at `bindPage()` and updated on each
|
|
158
|
+
`updateGlobalProps` notification, defaulting to `{}` when unset), isolating
|
|
159
|
+
each page in `LynxGroup` from peer pages. Inside
|
|
160
|
+
`page.onGlobalPropsChanged(props => ...)`, `props === page.getGlobalProps()`
|
|
161
|
+
always holds.
|
|
162
|
+
|
|
163
|
+
Treat the entire `GlobalProps` value—including nested objects—as read-only on both
|
|
164
|
+
threads (`Readonly<T>` is a compile-time marker and does not freeze objects). If a
|
|
165
|
+
DSL mutates its own root `GlobalProps` object in place (for example via
|
|
166
|
+
`Object.assign`), shallow-copy `{ ...getGlobalProps() }` or
|
|
167
|
+
`{ ...page.getGlobalProps() }` at startup so in-place root mutations do not write
|
|
168
|
+
back into the borrowed runtime snapshot.
|
|
169
|
+
|
|
170
|
+
## Raw BTS events
|
|
171
|
+
|
|
172
|
+
`page.setEventHandler(handler)` takes single-owner control of both page and
|
|
173
|
+
component event entries on its first registration; `bindPage()` alone does not
|
|
174
|
+
claim them. In this dispatcher fragment, `components` and `pageHandlers` are
|
|
175
|
+
registries owned by the DSL:
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
const stop = bindPage().setEventHandler((handlerName, data, componentId) => {
|
|
179
|
+
if (componentId !== undefined) {
|
|
180
|
+
return components.get(componentId)?.dispatch(handlerName, data);
|
|
181
|
+
}
|
|
182
|
+
return pageHandlers.get(handlerName)?.(data);
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
- Page events pass `componentId` as `undefined`; component events preserve the
|
|
187
|
+
host `componentId` string (including `""`).
|
|
188
|
+
- On MTS, elements must bind string handler names via `__AddEvent` or `__SetEvents`
|
|
189
|
+
to route events to BTS `setEventHandler`; `__AddEventListener` only accepts
|
|
190
|
+
MTS-local closures and does not forward string handler names to BTS.
|
|
191
|
+
- First registration claims both host event slots; a newer registration replaces
|
|
192
|
+
the previous one, and stale disposers are no-ops. Disposal or page destruction
|
|
193
|
+
resets both entries to return `undefined` without restoring prior handlers.
|
|
194
|
+
- Synchronous return values and thrown exceptions propagate directly to the host
|
|
195
|
+
(consumed by Native callbacks that inspect event results; Web event RPC is
|
|
196
|
+
one-way); `false` is treated as ordinary data, and `Promise`/thenable return
|
|
197
|
+
values are not awaited.
|
|
198
|
+
|
|
199
|
+
## BTS host global events (`page.onGlobalEvent`)
|
|
200
|
+
|
|
201
|
+
`page.onGlobalEvent<Args extends unknown[] = unknown[]>(name, listener)` subscribes
|
|
202
|
+
to host/client global events delivered to this page's `GlobalEventEmitter` (such as
|
|
203
|
+
client `sendGlobalEvent`, `exposure` / `disexposure`, and `keyboardstatuschanged`):
|
|
204
|
+
|
|
205
|
+
- Resolves `GlobalEventEmitter` from the bound page (`app.getJSModule('GlobalEventEmitter')`
|
|
206
|
+
/ `app.GlobalEventEmitter` before falling back to a page-bound `lynx.getJSModule('GlobalEventEmitter')`),
|
|
207
|
+
so asynchronous subscriptions in a shared `LynxGroup` context stay isolated from
|
|
208
|
+
peer pages. Missing `GlobalEventEmitter` fails explicitly.
|
|
209
|
+
- Lazily attaches one shared host listener per event `name` on that page and
|
|
210
|
+
deduplicates identical `(name, listener)` pairs. Host `removeListener` is invoked
|
|
211
|
+
only when the last Runtime subscriber for `name` unsubscribes or when page
|
|
212
|
+
destruction begins, avoiding premature host capability teardown across Runtime
|
|
213
|
+
subscribers (such as disabling `keyboardstatuschanged` detection while another
|
|
214
|
+
`page.onGlobalEvent` subscriber on the same page remains active) and in-place
|
|
215
|
+
listener-array mutation hazards during dispatch. Route all global-event
|
|
216
|
+
listeners on the page through `page.onGlobalEvent` rather than mixing raw
|
|
217
|
+
`GlobalEventEmitter` calls.
|
|
218
|
+
- Forwards all positional arguments emitted by the host with `undefined` `this`.
|
|
219
|
+
Does not replay events emitted before registration, and removes all listeners
|
|
220
|
+
before DSL `onDestroy` callbacks run.
|
|
221
|
+
|
|
222
|
+
## Registration lifetime
|
|
223
|
+
|
|
224
|
+
Load a single `@lynx-js/lynx-runtime` module instance per thread context so
|
|
225
|
+
subscriptions and single-owner slots share one per-host/per-page registry.
|
|
226
|
+
Host notifications deduplicate the same callback per page and notification.
|
|
227
|
+
Repeated `bindPage()` calls for the same page return the same `BTSPageRuntime`
|
|
228
|
+
handle and share registrations; a new registration after disposal cannot be
|
|
229
|
+
removed by old disposers. Because in-place page reloads (`onReload`:
|
|
230
|
+
`ReloadTemplate` / `ReloadFromJS`) do not trigger host `__DestroyLifetime`
|
|
231
|
+
(`onDestroy`), runtime managers that are recreated across reloads or entry
|
|
232
|
+
re-evaluations must invoke the returned `Unsubscribe` disposer when retiring an
|
|
233
|
+
older instance.
|
|
234
|
+
|
|
235
|
+
Unsubscribing prevents callbacks that have not yet started, including those in
|
|
236
|
+
the current dispatch. It does not interrupt a callback already running.
|
|
237
|
+
Registrations added during dispatch start with the next notification; they do not
|
|
238
|
+
receive the current input.
|
|
239
|
+
|
|
240
|
+
Once destruction begins, `isDestroyed()` (on MTS and `BTSPageRuntime`) immediately
|
|
241
|
+
returns `true` before any DSL `onDestroy` callback runs, while new listeners,
|
|
242
|
+
owners, messages, flushes, and capability activations throw. Existing disposers
|
|
243
|
+
stay safe and idempotent. MTS stops messages first,
|
|
244
|
+
invokes user `onDestroy` callbacks, and clears input listeners and resets
|
|
245
|
+
single-owner slots (`processData` to passthrough, `getPageData` to `null`) in
|
|
246
|
+
`finally`.
|
|
247
|
+
|
|
248
|
+
## Peer messages
|
|
249
|
+
|
|
250
|
+
MTS and `BTSPageRuntime` expose symmetric `sendMessage` and
|
|
251
|
+
`onMessage<T = unknown>(type, listener)`. When an explicit non-optional payload
|
|
252
|
+
type `T` is provided (`sendMessage<Payload>(type, data)`), `data` is required at
|
|
253
|
+
compile time. Messages target the peer thread of the same page (`lynx.getJSContext()`
|
|
254
|
+
on MTS, `lynx.getCoreContext()` on BTS). Install both receivers before sending.
|
|
255
|
+
|
|
256
|
+
- Messages pass `{ type, data }` directly through `ContextProxy.dispatchEvent`
|
|
257
|
+
without envelopes, prefixes, startup queues, acknowledgements, or `Promise` RPC,
|
|
258
|
+
and do not wrap legacy named-global `callLepusMethod` bridges.
|
|
259
|
+
- Listeners receive `event.data` verbatim (including `undefined` and `null`) with
|
|
260
|
+
`undefined` `this`.
|
|
261
|
+
- Subscriptions share one host listener per message `type` and deduplicate identical
|
|
262
|
+
callbacks. Missing peer context proxies fail explicitly.
|
|
263
|
+
- `T` is a caller-supplied TypeScript contract, not runtime payload validation.
|
|
264
|
+
`await sendMessage(...)` does not wait for the receiver. If completion matters,
|
|
265
|
+
define a reply and its meaning in the DSL protocol; timeout alone cannot prove
|
|
266
|
+
that the peer did not apply an operation.
|
|
267
|
+
|
|
268
|
+
## Page-level flush (`flushElementTree`)
|
|
269
|
+
|
|
270
|
+
MTS exposes `flushElementTree(options?: Readonly<MTSFlushOptions>): void` to submit
|
|
271
|
+
page-level element tree updates after `onUpdateData`, `onReload`,
|
|
272
|
+
`onGlobalPropsChanged`, or `onMessage` (first-screen `onRenderPage` is flushed
|
|
273
|
+
implicitly by the host when the callback returns).
|
|
274
|
+
|
|
275
|
+
- **Host update flush contract**: Every MTS `onUpdateData`, `onReload`, and
|
|
276
|
+
`onGlobalPropsChanged` handler that owns page updates must submit a corresponding
|
|
277
|
+
`flushElementTree(options)` call with the originating `options`—even when no
|
|
278
|
+
element attributes changed in that update—so the host's `nativeUpdateDataOrder`
|
|
279
|
+
queue and pipeline lifecycle remain aligned. Deferred flushes must retain and
|
|
280
|
+
forward the originating `options`.
|
|
281
|
+
- **Retirement and failure**: If rendering returns normally while the host remains
|
|
282
|
+
alive, retiring the entry during that render does not cancel the current update's
|
|
283
|
+
submission. If rendering throws, the DSL owns recovery and decides whether the
|
|
284
|
+
resulting tree can be submitted. Host destruction prevents further flushes.
|
|
285
|
+
- Calling `flushElementTree()` (or `flushElementTree(undefined)`) invokes
|
|
286
|
+
`__FlushElementTree()` with 0 arguments; calling `flushElementTree(options)`
|
|
287
|
+
validates that `options` is a plain object and invokes
|
|
288
|
+
`__FlushElementTree(undefined, options)` at the page root.
|
|
289
|
+
- If `options.timingFlag` is provided without `__lynx_timing_flag`, Runtime maps it
|
|
290
|
+
to `__lynx_timing_flag` on a shallow copy without mutating the caller's object;
|
|
291
|
+
otherwise `options` is passed through by reference.
|
|
292
|
+
- `MTSFlushOptions` extends `MTSFlushContext` (`reloadTemplate`,
|
|
293
|
+
`nativeUpdateDataOrder`, `pipelineOptions`) and adds page-level flush controls
|
|
294
|
+
(`timingFlag`, `triggerLayout`, `triggerDataUpdated`, `emptyPatch`). List subtree
|
|
295
|
+
flush options and `onLayoutReady` are excluded.
|
|
296
|
+
- `flushElementTree` returning only indicates that the flush request was submitted
|
|
297
|
+
to the host, not that layout or UI painting has completed.
|
|
298
|
+
|
|
299
|
+
## Native data processing & host updates
|
|
300
|
+
|
|
301
|
+
Register synchronous MTS hooks before the first host input when needed:
|
|
302
|
+
|
|
303
|
+
- `setDataProcessor(processor)`: Single-owner MTS `processData` hook. Normalizes
|
|
304
|
+
absent host data (`undefined` / `null`) to `{}` and empty default `processorName`
|
|
305
|
+
(`""`) to `undefined` across Native and Web. Data processors run synchronously on
|
|
306
|
+
MTS only; `PromiseLike` return types are rejected at compile time.
|
|
307
|
+
- `setPageDataGetter(getter)`: Single-owner MTS `getPageData` hook for host
|
|
308
|
+
page-data queries (`PromiseLike` return types rejected).
|
|
309
|
+
|
|
310
|
+
On first screen, `page.getInitData()` combines static template `initData` with the
|
|
311
|
+
initial `updateData` already processed by the host (while MTS `getInitData()`
|
|
312
|
+
captures the initial `renderPage` payload). On `onReload`, MTS `getInitData()`
|
|
313
|
+
replaces its baseline with a detached copy of that reload's payload, while BTS
|
|
314
|
+
`page.getInitData()` overlays that reload's payload onto the template's static
|
|
315
|
+
`_params.initData`. `page.onUpdateData()` subscribes directly to `tt.updateCardData`
|
|
316
|
+
(normalizing `resetPageData` and `processorName`) without an MTS-to-BTS forwarding
|
|
317
|
+
queue (requires `REACT_NODIFF` bundle DSL on Native, used by Rspeedy/ReactLynx,
|
|
318
|
+
`@lynx-js/rspeedy` Vanilla, and `.lynxml` on hosts that build LynxML bundles as
|
|
319
|
+
`REACT_NODIFF`; legacy `REACT` bundles skip BTS `updateCardData`).
|
|
320
|
+
|
|
321
|
+
## Host services (`getSystemInfo`, `createPipeline`, `markTiming`)
|
|
322
|
+
|
|
323
|
+
- `getSystemInfo(): Readonly<LynxSystemInfo>`:
|
|
324
|
+
- Returns live host `SystemInfo` across MTS (`lynx.SystemInfo`, keeping
|
|
325
|
+
`globalThis.SystemInfo` aliased for live `pixelRatio` updates when unset) and
|
|
326
|
+
BTS (`lynx.SystemInfo ?? globalThis.SystemInfo`), falling back to `{}`.
|
|
327
|
+
- `createPipeline(options?: CreatePipelineOptions): CreatedPipelineOptions | undefined`:
|
|
328
|
+
- Wraps host pipeline generation, `_onPipelineStart` signature differences across
|
|
329
|
+
MTS/BTS and SDK versions, and `timingFlag` binding (`ID` vs `Id`).
|
|
330
|
+
- Returns `undefined` when the host/page is destroying or destroyed, or when
|
|
331
|
+
pipeline generation is unavailable.
|
|
332
|
+
- `markTiming(pipeline: string | PipelineOptions | undefined, timingKey: string): void`:
|
|
333
|
+
- Accepts either a `pipelineID` string or a `PipelineOptions` object and records
|
|
334
|
+
`timingKey`, safely no-oping when unavailable or after destruction starts.
|
|
335
|
+
- Direct-reuse host globals (used directly without Runtime wrappers):
|
|
336
|
+
- `lynx.performance.profileStart` / `profileEnd` / `profileMark` /
|
|
337
|
+
`profileFlowId` / `isProfileRecording`, and `lynx.performance.createObserver`
|
|
338
|
+
on BTS (avoid calling `observe()` again after `disconnect()` on the same
|
|
339
|
+
observer instance);
|
|
340
|
+
- `lynx.fetchBundle` (`ResponseHandler.then` is callback-only, not a `Promise`),
|
|
341
|
+
`lynx.loadScript` (pass an explicit options object `lynx.loadScript(key, {})`
|
|
342
|
+
on BTS), and `lynx.getCustomSectionSync`;
|
|
343
|
+
- Standard timers (`setTimeout`, `clearTimeout`, `setInterval`, `clearInterval`,
|
|
344
|
+
`requestAnimationFrame`, `cancelAnimationFrame`) and `lynx.reportError`.
|
|
345
|
+
|
|
346
|
+
## Data ownership summary
|
|
347
|
+
|
|
348
|
+
- `getInitData()` returns detached copies of plain records and arrays for mutable
|
|
349
|
+
DSL state; opaque objects (`Date`, typed arrays, class instances) remain shared by
|
|
350
|
+
reference.
|
|
351
|
+
- `getGlobalProps()`, `getSystemInfo()`, and all notification payloads
|
|
352
|
+
(`onRenderPage`, `onUpdateData`, `onReload`, `onGlobalPropsChanged`,
|
|
353
|
+
`onConfigChanged`) are typed as `Readonly<...>` and must not be mutated in place.
|
|
354
|
+
- `page.getId()` returns the host identifier captured at binding (`appGUID`, then
|
|
355
|
+
`nativeAppId`, or `""` when absent).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/bts/data.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { subscribeBTSSlot } from "./scope.js";
|
|
2
|
+
function scopeOnGlobalPropsChanged(scope, listener) {
|
|
3
|
+
return subscribeBTSSlot(scope, 'updateGlobalProps', ()=>{
|
|
4
|
+
listener(scope.globalProps);
|
|
5
|
+
}, listener);
|
|
6
|
+
}
|
|
7
|
+
function scopeOnUpdateData(scope, listener) {
|
|
8
|
+
return subscribeBTSSlot(scope, 'updateCardData', (data, rawOptions)=>{
|
|
9
|
+
listener(data ?? {}, {
|
|
10
|
+
resetPageData: rawOptions?.type === 1,
|
|
11
|
+
processorName: rawOptions?.processorName === '' ? void 0 : rawOptions?.processorName
|
|
12
|
+
});
|
|
13
|
+
}, listener);
|
|
14
|
+
}
|
|
15
|
+
function scopeOnReload(scope, listener) {
|
|
16
|
+
return subscribeBTSSlot(scope, 'onAppReload', (data, options)=>{
|
|
17
|
+
listener(data ?? {}, options ? {
|
|
18
|
+
...options,
|
|
19
|
+
processorName: '' === options.processorName ? void 0 : options.processorName
|
|
20
|
+
} : {});
|
|
21
|
+
}, listener);
|
|
22
|
+
}
|
|
23
|
+
function scopeOnConfigChanged(scope, listener) {
|
|
24
|
+
return subscribeBTSSlot(scope, 'processCardConfig', (config)=>{
|
|
25
|
+
listener(config ?? {});
|
|
26
|
+
}, listener);
|
|
27
|
+
}
|
|
28
|
+
export { scopeOnConfigChanged, scopeOnGlobalPropsChanged, scopeOnReload, scopeOnUpdateData };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { assertScopeAlive, getScopeLynx } from "./scope.js";
|
|
2
|
+
import { subscribeMultiplexed } from "../common/messages.js";
|
|
3
|
+
function createEventEntry() {
|
|
4
|
+
const dispatch = (handlerName, data, componentId)=>{
|
|
5
|
+
const handler = entry.current?.handler;
|
|
6
|
+
return handler?.(handlerName, data, componentId);
|
|
7
|
+
};
|
|
8
|
+
const entry = {
|
|
9
|
+
current: void 0,
|
|
10
|
+
publishEvent: (handlerName, data)=>dispatch(handlerName, data),
|
|
11
|
+
publicComponentEvent: (componentId, handlerName, data)=>dispatch(handlerName, data, componentId)
|
|
12
|
+
};
|
|
13
|
+
return entry;
|
|
14
|
+
}
|
|
15
|
+
function scopeSetEventHandler(scope, handler) {
|
|
16
|
+
assertScopeAlive(scope);
|
|
17
|
+
let entry = scope.eventEntry;
|
|
18
|
+
if (!entry) {
|
|
19
|
+
entry = scope.eventEntry = createEventEntry();
|
|
20
|
+
scope.app.publishEvent = entry.publishEvent;
|
|
21
|
+
scope.app.publicComponentEvent = entry.publicComponentEvent;
|
|
22
|
+
}
|
|
23
|
+
const registration = {
|
|
24
|
+
handler: handler
|
|
25
|
+
};
|
|
26
|
+
entry.current = registration;
|
|
27
|
+
const currentEntry = entry;
|
|
28
|
+
return ()=>{
|
|
29
|
+
if (currentEntry.current === registration) currentEntry.current = void 0;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function getGlobalEventEmitter(scope) {
|
|
33
|
+
let emitter = scope.app.getJSModule?.('GlobalEventEmitter') ?? scope.app.GlobalEventEmitter;
|
|
34
|
+
if (!emitter) {
|
|
35
|
+
const scopeLynx = getScopeLynx(scope);
|
|
36
|
+
if (scopeLynx && (!scopeLynx.getApp || scopeLynx.getApp() === scope.app)) emitter = scopeLynx.getJSModule?.('GlobalEventEmitter');
|
|
37
|
+
}
|
|
38
|
+
if (!emitter) throw new Error("[@lynx-js/lynx-runtime/bts] Global event subscription requires GlobalEventEmitter. Ensure the BTS host environment is initialized before calling onGlobalEvent().");
|
|
39
|
+
return emitter;
|
|
40
|
+
}
|
|
41
|
+
function scopeOnGlobalEvent(scope, name, listener) {
|
|
42
|
+
assertScopeAlive(scope);
|
|
43
|
+
scope.globalEvents ??= new Map();
|
|
44
|
+
return subscribeMultiplexed(scope.globalEvents, name, listener, (dispatch)=>{
|
|
45
|
+
const emitter = getGlobalEventEmitter(scope);
|
|
46
|
+
const onEvent = (...args)=>{
|
|
47
|
+
dispatch((fn)=>{
|
|
48
|
+
fn(...args);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
emitter.addListener(name, onEvent);
|
|
52
|
+
return ()=>{
|
|
53
|
+
emitter.removeListener(name, onEvent);
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export { scopeOnGlobalEvent, scopeSetEventHandler };
|