Skip to content

Commit 8e32559

Browse files
committed
doc: Improve documentation of code.
1 parent c016331 commit 8e32559

30 files changed

Lines changed: 232 additions & 139 deletions

packages/flutter_reactter/example/lib/animation/animation_controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class AnimationController {
6565
),
6666
);
6767

68-
late final isPlaying = Reactter.lazy(() {
68+
late final isPlaying = Reactter.lazyState(() {
6969
return UseCompute(
7070
() => [
7171
sizeAnimation.control.value,

packages/flutter_reactter/example/lib/animation/use_animation.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ class UseAnimation<T> extends ReactterHook implements TickerProvider {
6262
@protected
6363
final $ = ReactterHook.$register;
6464

65-
late final tween = Reactter.lazy(() => UseState(options.tween), this);
66-
late final control = Reactter.lazy(() => UseState(options.control), this);
67-
late final duration = Reactter.lazy(() => UseState(options.duration), this);
68-
late final curve = Reactter.lazy(() => UseState(options.curve), this);
65+
late final tween = Reactter.lazyState(() => UseState(options.tween), this);
66+
late final control =
67+
Reactter.lazyState(() => UseState(options.control), this);
68+
late final duration =
69+
Reactter.lazyState(() => UseState(options.duration), this);
70+
late final curve = Reactter.lazyState(() => UseState(options.curve), this);
6971

7072
bool _waitForDelay = true;
7173
Set<Ticker>? _tickers;

packages/flutter_reactter/example/lib/api/api_page.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:flutter/material.dart';
1+
import 'package:flutter/material.dart' hide SearchBar;
22
import 'package:flutter_reactter/flutter_reactter.dart';
33

44
import 'controllers/api_controller.dart';
@@ -35,7 +35,7 @@ class ApiPage extends StatelessWidget {
3535
padding: const EdgeInsets.all(8),
3636
child: Center(
3737
child: ReactterConsumer<ApiController>(
38-
listenStates: (inst) => [inst.entity],
38+
listenStates: (inst) => [inst.entityState],
3939
builder: (_, __, ___) {
4040
return FittedBox(
4141
child: SizedBox(
@@ -45,7 +45,7 @@ class ApiPage extends StatelessWidget {
4545
child: Container(
4646
alignment: Alignment.center,
4747
padding: const EdgeInsets.all(16),
48-
child: apiController.entity.when<Widget>(
48+
child: apiController.entityState.when<Widget>(
4949
standby: (_) => const Text(
5050
'Search a user or repository(like "flutter/flutter")',
5151
),

packages/flutter_reactter/example/lib/api/controllers/api_controller.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ class ApiController {
66
String _query = '';
77
String get query => _query;
88

9-
final entity = UseAsyncState.withArgs(
9+
final entityState = UseAsyncState.withArg(
1010
null,
11-
Reactter.memo(ApiService().getEntity.ary),
11+
Memo.inline<Future<Object?>, Args1<String>>(
12+
ApiService().getEntity.ary,
13+
const MemoInterceptors([
14+
AsyncMemoSafe(),
15+
TemporaryCacheMemo(Duration(seconds: 30)),
16+
]),
17+
),
1218
);
1319

1420
void search(String query) {
1521
_query = query;
16-
entity.resolve(Args1(query));
22+
entityState.resolve(Args1(query));
1723
}
1824
}

packages/flutter_reactter/example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final items = [
6262
"Search user or repository and show info about it.",
6363
[
6464
"Generic arguments",
65-
"Reactter.memo",
65+
"Memo",
6666
"ReactterConsumer",
6767
"ReactterProvider",
6868
"UseAsyncState",

packages/flutter_reactter/example/lib/todo/controllers/todo_controller.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class TodoController {
2424
),
2525
);
2626

27-
late final todoListFiltered = Reactter.lazy(
27+
late final todoListFiltered = Reactter.lazyState(
2828
() => UseCompute(
2929
() => getTodosBy(state.value.filterBy),
3030
[state],
3131
),
3232
this,
3333
);
3434

35-
late final todoActiveCount = Reactter.lazy(
35+
late final todoActiveCount = Reactter.lazyState(
3636
() => UseCompute(
3737
() => state.value.todoList.fold<int>(
3838
0,

packages/flutter_reactter/lib/src/extensions/build_context_extension.dart

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ part of '../extensions.dart';
22

33
/// Exposes methods to helps to get and listen the Object instance.
44
extension ReactterBuildContextExtension on BuildContext {
5-
/// Gets the [T] instance from the closest ancestor of [ReactterProvider]
6-
/// and watches instance changes or [ReactterState] defined
7-
/// in first paramater([listenStates]) to re-render the Widget tree.
5+
/// Gets the instance of [T] type from the closest ancestor of [ReactterProvider]
6+
/// and listens changes to the instance or the states([ReactterState]) defined
7+
/// in first parameter([listenStates]) to trigger re-render of the Widget tree.
88
///
99
/// ```dart
1010
/// final appController = context.watch<AppController>();
11-
/// final appControllerWatchState = context.watch<AppController>((inst) => [inst.stateA]);
11+
/// final appControllerWatchStates = context.watch<AppController>(
12+
/// (inst) => [inst.stateA],
13+
/// );
1214
/// final appControllerNullable = context.wath<AppController?>();
1315
/// ```
1416
///
@@ -27,13 +29,17 @@ extension ReactterBuildContextExtension on BuildContext {
2729
return ReactterProvider.contextOf<T>(this, listenStates: listenStates);
2830
}
2931

30-
/// Gets the [T] instance by [id] from the closest ancestor of [ReactterProvider]
31-
/// and watches instance changes or [ReactterState] defined
32-
/// in second paramater([listenStates]) to re-render the Widget tree.
32+
/// Gets the instance of [T] type by [id] from the closest ancestor
33+
/// of [ReactterProvider] and watchs changes to the instance or
34+
/// the states([ReactterState]) defined in first parameter([listenStates])
35+
/// to trigger re-render of the Widget tree.
3336
///
3437
/// ```dart
3538
/// final appController = context.watchId<AppController>("UniqueId");
36-
/// final appControllerWatchHook = context.watchId<AppController>("UniqueId", (inst) => [inst.stateA]);
39+
/// final appControllerWatchHook = context.watchId<AppController>(
40+
/// "UniqueId",
41+
/// (inst) => [inst.stateA],
42+
/// );
3743
/// final appControllerNullable = context.wathId<AppController?>("UniqueId");
3844
/// ```
3945
///
@@ -59,7 +65,7 @@ extension ReactterBuildContextExtension on BuildContext {
5965
);
6066
}
6167

62-
/// Gets the [T] instance with/without [id]
68+
/// Gets the instance of [T] type with/without [id]
6369
/// from the closest ancestor of [ReactterProvider].
6470
///
6571
/// ```dart
@@ -87,7 +93,7 @@ extension ReactterBuildContextExtension on BuildContext {
8793
/// The error that will be thrown if [ReactterProvider.contextOf] fails
8894
/// to find the instance from ancestor of the [BuildContext] used.
8995
class ReactterInstanceNotFoundException implements Exception {
90-
ReactterInstanceNotFoundException(
96+
const ReactterInstanceNotFoundException(
9197
this.valueType,
9298
this.widgetType,
9399
);

packages/flutter_reactter/lib/src/extensions/reactter_state_list_extension.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
part of '../extensions.dart';
22

33
extension ReactterStateListExtension<E extends ReactterState> on List<E> {
4-
/// Takes multiple conditions as arguments and returns a list of
5-
/// [UseCompute] objects based on those conditions.
4+
/// Takes multiple conditions and returns a list of [UseCompute] based
5+
/// on theses conditions.
66
///
77
/// Generally, it's used to listen for conditional states using [context.watch]:
88
///
@@ -16,7 +16,10 @@ extension ReactterStateListExtension<E extends ReactterState> on List<E> {
1616
/// () => inst.stateB.value == 'Y', // condition3
1717
/// ),
1818
/// );
19+
///
1920
/// ```
21+
/// Use [UseCompute] instead to improve performance, creating it out of
22+
/// context.
2023
List<UseCompute> when(
2124
dynamic Function() condition, [
2225
dynamic Function()? condition2,

packages/flutter_reactter/lib/src/widgets/reactter_component.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
part of '../widgets.dart';
22

3+
/// {@template reactter_component}
34
/// A abstract [StatelessWidget] class that provides [ReactterProvider] features,
4-
/// whose [T] instance defined is exposing trough [render] method.
5+
/// whose instance of [T] type defined is exposing trough [render] method.
56
///
67
/// ```dart
78
/// class App extends ReactterComponent<AppController> {
@@ -53,8 +54,8 @@ part of '../widgets.dart';
5354
/// }
5455
/// ```
5556
///
56-
/// Use [listenAll] getter as `true` to listen all the [T] instance changes
57-
/// to rebuild the Widget tree defined in [render] method.
57+
/// Use [listenAll] getter as `true` to listen all instance changes to rebuild
58+
/// the Widget tree defined in [render] method.
5859
///
5960
/// ```dart
6061
/// class App extends ReactterComponent<AppController> {
@@ -69,8 +70,9 @@ part of '../widgets.dart';
6970
///
7071
/// See also:
7172
///
72-
/// * [ReactterProvider], a [StatelessWidget] that provides a [T] instance
73+
/// * [ReactterProvider], a [StatelessWidget] that provides an instance of [T] type
7374
/// to widget tree that can be access through the [BuildContext].
75+
/// {@endtemplate}
7476
abstract class ReactterComponent<T extends Object> extends StatelessWidget {
7577
const ReactterComponent({Key? key}) : super(key: key);
7678

packages/flutter_reactter/lib/src/widgets/reactter_consumer.dart

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
part of '../widgets.dart';
22

3-
/// A [StatelessWidget] that allows to obtains a [T] instance
4-
/// from the closest ancestor of [ReactterProvider]
5-
/// and passes the instance to [builder].
3+
/// {@template reactter_consumer}
4+
/// A [StatelessWidget] that allows to obtains an instance of [T] type
5+
/// from the closest ancestor of [ReactterProvider] and passes the instance
6+
/// to [builder].
67
///
7-
/// Also, it listens for changes from the instance or a [ReactterState] list
8-
/// to rebuild the Widget tree.
8+
/// Also, listens for instance changes or a [ReactterState] list
9+
/// to rebuild the widget tree.
910
///
1011
/// [ReactterConsumer] has same functionality as [ReactterProvider.contextOf].
1112
///
1213
/// Use [id] property to identify the [T] instance.
1314
///
14-
/// Use [listenAll] property for listen to changes from the instance
15-
/// or states defined in [listenStates] property:
15+
/// Use [listenAll] property to listen changes to the instance
16+
/// or the states defined in [listenStates] property:
1617
///
1718
///```dart
1819
/// ReactterConsumer<AppController>(
@@ -29,7 +30,8 @@ part of '../widgets.dart';
2930
/// ```
3031
///
3132
/// Use [child] property to pass a [Widget] which to be built once only.
32-
/// It will be sent through the [builder] callback, so you can incorporate it into your build:
33+
/// It will be sent through the [builder] callback, so you can incorporate it
34+
/// into your build:
3335
///
3436
///```dart
3537
/// ReactterConsumer<AppController>(
@@ -49,9 +51,11 @@ part of '../widgets.dart';
4951
/// See also:
5052
///
5153
/// * [ReactterState], a state in reactter.
52-
/// * [ReactterProvider], a widget that provides a [T] instance through Widget tree.
53-
///
54+
/// * [ReactterProvider], a widget that provides a [T] instance through Widget
55+
/// tree.
56+
///{@endtemplate}
5457
class ReactterConsumer<T extends Object?> extends StatelessWidget {
58+
/// {@macro reactter_consumer}
5559
const ReactterConsumer({
5660
Key? key,
5761
this.id,

0 commit comments

Comments
 (0)