platform/jael_web/example/stateful.dart

33 lines
646 B
Dart
Raw Normal View History

2019-03-23 18:49:37 +00:00
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);
}
}
2019-03-23 22:02:57 +00:00
@Jael(template: '<div>Tick count: {{state.ticks}}</div>')
2019-03-23 18:49:37 +00:00
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();
}
}