-
Notifications
You must be signed in to change notification settings - Fork 123
feat: implement global-bind event support for decoupled cross-element… #2438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
PupilTong
merged 8 commits into
lynx-family:main
from
PupilTong:p/hw/support-global-bind
Apr 10, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2515044
feat: implement global-bind event support for decoupled cross-element…
PupilTong b81ef69
+ fix
PupilTong bfaf138
+ fix
PupilTong 08055fb
+ fix
PupilTong 806b09d
+ fix
PupilTong cd17a16
+ fix
PupilTong 4daebc8
refactor: decouple global event iteration from collection lookup to i…
PupilTong 0601e37
test: add test case for global-bind events with run-worklet handlers
PupilTong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --- | ||
| "@lynx-js/web-core": patch | ||
| --- | ||
|
|
||
| Added support for the `global-bind` event handling modifier in the web platform runtime. | ||
|
|
||
| This mechanism enables seamless cross-element event communication without requiring a formal DOM tree relationship, allowing decoupled elements to observe and respond to standard events occurring anywhere within the component tree. | ||
|
|
||
| ### Usage | ||
|
|
||
| Global bindings allow an observer element to react to events triggered on another target element. | ||
|
|
||
| #### 1. Define the Global Subscription | ||
|
|
||
| Attach `global-bindTap` (or any equivalent standard event alias) to your observer element: | ||
|
|
||
| ```jsx | ||
| <view | ||
| id='observer' | ||
| global-bindTap={(event) => { | ||
| // This will trigger whenever 'tap' is caught by a globally bound event. | ||
| console.log('Global tap handled!', event); | ||
| }} | ||
| />; | ||
| ``` | ||
|
|
||
| #### 2. Trigger the Event anywhere | ||
|
|
||
| The event will be triggered via normal user interaction (such as `tap`) on any other constituent elements: | ||
|
|
||
| ```jsx | ||
| <view | ||
| id='target' | ||
| bindTap={(event) => { | ||
| // Note: To successfully propagate globally, ensure the event bubbles. | ||
| }} | ||
| />; | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| --- | ||
|
|
||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/web-platform/web-core-e2e/tests/reactlynx/basic-global-bind/index.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright 2023 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
| import { useState, root } from '@lynx-js/react'; | ||
|
|
||
| function App() { | ||
| const [color, setColor] = useState('pink'); | ||
| return ( | ||
| <view> | ||
| { | ||
| /* | ||
| This is the target element. | ||
| When clicking here, the 'tap' event bubbles and should trigger 'global-bindtap'. | ||
| */ | ||
| } | ||
| <view | ||
| id='target' | ||
| style={{ | ||
| height: '100px', | ||
| width: '100px', | ||
| background: 'blue', | ||
| }} | ||
| /> | ||
| { | ||
| /* | ||
| This is the observer element observing 'global-bindtap'. | ||
| */ | ||
| } | ||
| <view | ||
| id='observer' | ||
| global-bindTap={() => setColor(color === 'pink' ? 'green' : 'pink')} | ||
| style={{ | ||
| height: '100px', | ||
| width: '100px', | ||
| background: color, | ||
| }} | ||
| /> | ||
| </view> | ||
| ); | ||
| } | ||
|
|
||
| root.render(<App />); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.