Skip to content

Commit 45d75c1

Browse files
feat: Improve input element onInput typing, simplify @Attribute annotation, and fix method extraction in component generator.
1 parent 9d23036 commit 45d75c1

14 files changed

Lines changed: 449 additions & 133 deletions

File tree

packages/spark/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
## TBP
1+
## 1.0.0-alpha.2 - 22-01-2025
22

33
### Breaking changes
44

55
- There is a new way to write Components. Please refer to the [documentation](https://spark.kleak.dev/docs/components) for more information.
66

77
### Features
88

9+
- Add type to input element onInput event based on the type of the input
910
- Added support for cookies
1011
- Added support for csp nonce on scripts and styles
1112
- Fix @Component

packages/spark/example/lib/components/counter_final/config.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class CounterConfig {
2-
final int step;
3-
final int secondsOfDelay;
2+
final num step;
3+
final num secondsOfDelay;
44

55
const CounterConfig({this.step = 1, this.secondsOfDelay = 0});
66

packages/spark/example/lib/components/counter_final/counter_final_base.dart

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CounterFinal {
1414
});
1515

1616
@Attribute()
17-
int value;
17+
num value;
1818

1919
@Attribute()
2020
String label;
@@ -101,7 +101,9 @@ class CounterFinal {
101101
onClick: (_) async {
102102
isUpdating = true;
103103
if (config.secondsOfDelay > 0) {
104-
await Future.delayed(Duration(seconds: config.secondsOfDelay));
104+
await Future.delayed(
105+
Duration(seconds: config.secondsOfDelay.toInt()),
106+
);
105107
}
106108
value -= config.step;
107109
isUpdating = false;
@@ -115,7 +117,9 @@ class CounterFinal {
115117
onClick: (_) async {
116118
isUpdating = true;
117119
if (config.secondsOfDelay > 0) {
118-
await Future.delayed(Duration(seconds: config.secondsOfDelay));
120+
await Future.delayed(
121+
Duration(seconds: config.secondsOfDelay.toInt()),
122+
);
119123
}
120124
value += config.step;
121125
isUpdating = false;
@@ -124,26 +128,26 @@ class CounterFinal {
124128
]),
125129
div(className: 'step-controls', [
126130
span(['Step:']),
127-
input(
128-
attributes: {'type': 'number', 'value': config.step},
131+
input<int>(
132+
type: 'number',
133+
value: config.step.toInt(),
129134
className: 'step-input',
130135
onInput: (e) {
131-
final val = int.tryParse((e.target as HTMLInputElement).value) ?? 1;
132136
config = CounterConfig(
133-
step: val,
137+
step: e,
134138
secondsOfDelay: config.secondsOfDelay,
135139
);
136140
},
137141
),
138142
]),
139143
div(className: 'step-controls', [
140144
span(['Delay:']),
141-
input(
142-
attributes: {'type': 'number', 'value': config.secondsOfDelay},
145+
input<num>(
146+
type: 'number',
147+
value: config.secondsOfDelay,
143148
className: 'step-input',
144-
onInput: (e) {
145-
final val = int.tryParse((e.target as HTMLInputElement).value) ?? 1;
146-
config = CounterConfig(secondsOfDelay: val, step: config.step);
149+
onInput: (value) {
150+
config = CounterConfig(step: config.step, secondsOfDelay: value);
147151
},
148152
),
149153
]),

packages/spark/example/lib/components/counter_final/counter_final_base.impl.dart

Lines changed: 20 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/spark/example/lib/spark_router.g.dart

Lines changed: 35 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/spark/lib/spark.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
/// `SparkPage` class. See `package:spark/server.dart` for details.
5151
library;
5252

53-
export 'src/component/component.dart' hide Text, Element, Request, Response;
53+
export 'src/component/component.dart'
54+
hide Text, Element, Request, Response, Node;
5455
export 'src/utils/utils.dart';
5556
export 'src/annotations/annotations.dart';
5657
export 'src/page/page.dart';

0 commit comments

Comments
 (0)