-
Notifications
You must be signed in to change notification settings - Fork 795
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
fix(runtime): support "capture" style events #4968
Merged
+117
−5
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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,21 @@ | ||
import { Component, h, State } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'event-listener-capture', | ||
}) | ||
export class EventListenerCapture { | ||
@State() counter = 0; | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<p>Click the text below to trigger a capture style event</p> | ||
<div> | ||
<p id="incrementer" onClickCapture={() => this.counter++}> | ||
Clicked: <span id="counter">{this.counter}</span> time(s) | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
This file contains 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,6 @@ | ||
<!doctype html> | ||
<meta charset="utf8" /> | ||
<script src="./build/testapp.esm.js" type="module"></script> | ||
<script src="./build/testapp.js" nomodule></script> | ||
|
||
<event-listener-capture></event-listener-capture> |
This file contains 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,31 @@ | ||
import { setupDomTests, waitForChanges } from '../util'; | ||
|
||
describe('event-listener-capture', function () { | ||
const { setupDom, tearDownDom } = setupDomTests(document); | ||
|
||
let app: HTMLElement | undefined; | ||
let host: HTMLElement | undefined; | ||
|
||
beforeEach(async () => { | ||
app = await setupDom('/event-listener-capture/index.html'); | ||
host = app.querySelector('event-listener-capture'); | ||
}); | ||
|
||
afterEach(tearDownDom); | ||
|
||
it('should render', () => { | ||
expect(host).toBeDefined(); | ||
}); | ||
|
||
it('should increment counter on click', async () => { | ||
const counter = host.querySelector('#counter'); | ||
expect(counter.textContent).toBe('0'); | ||
|
||
const p = host.querySelector('#incrementer') as HTMLParagraphElement; | ||
expect(p).toBeDefined(); | ||
p.click(); | ||
await waitForChanges(); | ||
|
||
expect(counter.textContent).toBe('1'); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, couldn't we avoid the double assignment here of
capture
by using the conditional directly since we're always calling it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made that change, also just removed the conditional that would follow so we always just make the call to
replace
, just won't do anything if there's nothing to replace (obviously).