platform/packages/jael/jael_web/example/stateful.dart
Tobe O edfd785dfe Add 'packages/jael/' from commit 'af168281d94cda98a8fd333618696e92f4e035c5'
git-subtree-dir: packages/jael
git-subtree-mainline: 834de0300f
git-subtree-split: af168281d9
2020-02-15 18:22:11 -05:00

32 lines
647 B
Dart

import 'dart:async';
import 'package:jael_web/jael_web.dart';
part 'stateful.g.dart';
void main() {}
class _AppState {
final int ticks;
_AppState({this.ticks});
_AppState copyWith({int ticks}) {
return _AppState(ticks: ticks ?? this.ticks);
}
}
@Jael(template: '<div>Tick count: {{state.ticks}}</div>')
class StatefulApp extends Component<_AppState> with _StatefulAppJaelTemplate {
Timer _timer;
StatefulApp() {
state = _AppState(ticks: 0);
_timer = Timer.periodic(Duration(seconds: 1), (t) {
setState(state.copyWith(ticks: t.tick));
});
}
@override
void beforeDestroy() {
_timer.cancel();
}
}