DEV: Introduce a helper for handling events (#25433)

Instead of

```hbs
{{on "input" (action this.foo value="target.value")}}
{{on "input" (action (mut this.bar) value="target.value")}}
```

you can use:

```hbs
{{on "input" (with-event-value this.foo)}}
{{on "input" (with-event-value (fn (mut this.bar)))}}
```

or in gjs:

```gjs
import { fn } from "@ember/helper";
import { on } from "@ember/modifier";
import withEventValue from "discourse/helpers/with-event-value";
…
{{on "input" (withEventValue (fn (mut this.bar)))}}
```
This commit is contained in:
Jarek Radosz
2024-02-28 14:00:53 +01:00
committed by GitHub
parent 0e17ff8d09
commit 36a9b5d0fa
19 changed files with 42 additions and 62 deletions

View File

@ -1,10 +1,7 @@
<StyleguideExample @title="<CharCounter>">
<CharCounter @max="50" @value={{@dummy.charCounterContent}}>
<textarea
{{on
"input"
(action (mut @dummy.charCounterContent) value="target.value")
}}
{{on "input" (with-event-value (fn (mut @dummy.charCounterContent)))}}
class="styleguide--char-counter"
></textarea>
</CharCounter>