-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace input debouncing with a more robust mechanism for de-duplicat…
…ing queued user events
- Loading branch information
1 parent
b4944ca
commit 39cf4b3
Showing
7 changed files
with
111 additions
and
26 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import mesop as me | ||
|
||
|
||
@me.page(path="/input_race") | ||
def app(): | ||
state = me.state(State) | ||
me.input(key="a", label="Input a", on_input=on_input) | ||
me.input(key="b", label="Input b", on_input=on_input) | ||
me.button(label="Click", on_click=on_click) | ||
me.text("State.input_a: " + state.input_a) | ||
me.text("State.input_b: " + state.input_b) | ||
me.text("State.input_on_click: " + state.input_on_click) | ||
|
||
|
||
@me.stateclass | ||
class State: | ||
input_a: str | ||
input_b: str | ||
input_on_click: str | ||
|
||
|
||
def on_input(e: me.InputEvent): | ||
state = me.state(State) | ||
if e.key == "a": | ||
state.input_a = e.value | ||
elif e.key == "b": | ||
state.input_b = e.value | ||
|
||
|
||
def on_click(e: me.ClickEvent): | ||
state = me.state(State) | ||
state.input_on_click = state.input_a |
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,29 @@ | ||
import {test, expect} from '@playwright/test'; | ||
|
||
test('test', async ({page}) => { | ||
// This test is relatively slower because there's a few | ||
// sequential steps. | ||
test.setTimeout(30000); | ||
|
||
await page.goto('/input_race'); | ||
|
||
// Trigger an initial user event. | ||
await page.getByLabel('Input a').fill('1'); | ||
// Trigger two user events "2", "3" which will | ||
// probably get queued. | ||
await page.getByLabel('Input a').pressSequentially('23'); | ||
// Trigger a user event with the same handler function | ||
// but different key to check that this edge case is handled. | ||
await page.getByLabel('Input b').fill('45'); | ||
// Trigger a click user event to save the value of Input a. | ||
await page.getByRole('button', {name: 'Click'}).click(); | ||
|
||
// Assert that the text for each field is as expected. | ||
await expectTextExists('State.input_a: 123'); | ||
await expectTextExists('State.input_b: 45'); | ||
await expectTextExists('State.input_on_click: 123'); | ||
|
||
async function expectTextExists(text: string) { | ||
expect(await page.getByText(text).textContent()).toEqual(text); | ||
} | ||
}); |
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