Skip to content

Commit 558ea96

Browse files
committed
refactor: Replace createState with registerState.
1 parent 227a7a7 commit 558ea96

File tree

25 files changed

+58
-58
lines changed

25 files changed

+58
-58
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- Add [`debugLabel`](https://pub.dev/documentation/reactter/8.0.0-dev.31/reactter/RtState/debugLabel.html) and [`debugInfo`](https://pub.dev/documentation/reactter/8.0.0-dev.31/reactter/RtState/debugInfo.html) to states and hooks to get info for debugging.
1414
- Add [`RtContextMixin`](https://pub.dev/documentation/reactter/8.0.0-dev.31/reactter/RtContextMixin-mixin.html) mixin to provide access to the `Rt` instance.
1515
- Add [`RtState`](https://pub.dev/documentation/reactter/8.0.0-dev.31/reactter/RtState-class.html) abstract class to implement the base logic of the state.
16-
- Add [`Rt.createState`](https://pub.dev/documentation/reactter/8.0.0-dev.31/reactter/RtInterface/createState.html) method to create a new state.
16+
- Add [`Rt.registerState`](https://pub.dev/documentation/reactter/8.0.0-dev.31/reactter/RtInterface/registerState.html) method to create a new state.
1717
- Add [`Rt.getRefAt`](https://pub.dev/documentation/reactter/8.0.0-dev.31/reactter/RtInterface/getRefAt.html) to get the reference of dependency created.
1818
- Add [`initHook`](https://pub.dev/documentation/reactter/8.0.0-dev.31/reactter/RtHook/initHook.html) method to `RtHook` to call when hook is created.
1919
- Add [`cancel`](https://pub.dev/documentation/reactter/8.0.0-dev.31/reactter/UseAsyncState/cancel.html) method to `UseAsyncState` to cancel current method.

packages/flutter_reactter/example/lib/examples/6_tree/states/tree_list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class TreeList extends LinkedList<TreeNode> with RtState {
77
TreeList._();
88

99
factory TreeList() {
10-
return Rt.createState(() => TreeList._());
10+
return Rt.registerState(() => TreeList._());
1111
}
1212

1313
@override

packages/flutter_reactter/example/lib/examples/6_tree/states/tree_node.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class TreeNode extends LinkedListEntry<TreeNode> with RtState {
8080
/// and keep it in memory until it is destroyed.
8181
factory TreeNode([TreeNode? parent]) {
8282
return Rt.singleton(
83-
() => Rt.createState(() {
83+
() => Rt.registerState(() {
8484
return TreeNode._(parent);
8585
}),
8686
id: _lastId.toString(),

packages/reactter/lib/src/core/state_management.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ abstract class StateManagement<S extends IState> implements IContext {
1414

1515
final LinkedHashMap<EventNotifier, Object?> _deferredEvents = LinkedHashMap();
1616

17-
/// Creates a new state by invoking the provided `buildState` function.
17+
/// Register a new state by invoking the provided `buildState` function.
1818
///
1919
/// The `buildState` function should return an instance of a class that extends [S].
20-
/// The created state is automatically bound to the current binding zone using `BindingZone.autoBinding`.
20+
/// The register state is automatically bound to the current binding zone using `BindingZone.autoBinding`.
2121
///
2222
/// Example usage:
2323
/// ```dart
@@ -30,11 +30,11 @@ abstract class StateManagement<S extends IState> implements IContext {
3030
/// }
3131
/// }
3232
///
33-
/// final state = Rt.createState<MyState>(() => MyState());
33+
/// final state = Rt.registerState<MyState>(() => MyState());
3434
/// ```
3535
///
36-
/// Returns the created state.
37-
T createState<T extends S>(T Function() buildState) {
36+
/// Returns [T] state.
37+
T registerState<T extends S>(T Function() buildState) {
3838
return BindingZone.autoBinding(buildState);
3939
}
4040

packages/reactter/lib/src/framework/rt_state.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ part of '../internals.dart';
33
/// {@template reactter.rt_state}
44
/// A base class for creating a state object in Reactter.
55
///
6-
/// The state object must be registered using the [Rt.createState] method or
6+
/// The state object must be registered using the [Rt.registerState] method or
77
/// registered as a dependency using the dependency injection. e.g.
88
///
99
/// ```dart
@@ -16,11 +16,11 @@ part of '../internals.dart';
1616
/// }
1717
/// }
1818
///
19-
/// final state = Rt.createState<MyState>(() => MyState());
19+
/// final state = Rt.registerState<MyState>(() => MyState());
2020
/// ```
2121
///
2222
/// See also:
23-
/// - [Rt.createState], for creating a state object.
23+
/// - [Rt.registerState], for register a state object.
2424
///
2525
/// {@endtemplate}
2626
abstract class RtState implements IState {
@@ -36,7 +36,7 @@ abstract class RtState implements IState {
3636
if (!isRegistering) {
3737
throw AssertionError(
3838
"The state must be create within the BindingZone.\n"
39-
"You can use the 'Rt.createState' method or register as dependency "
39+
"You can use the 'Rt.registerState' method or register as dependency "
4040
"using the dependency injection to ensure that the state is registered.",
4141
);
4242
}

packages/reactter/lib/src/signal/signal.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Signal<T> with RtState {
125125
_debugLabel = debugLabel;
126126

127127
factory Signal(T value, {String? debugLabel}) {
128-
return Rt.createState(() => Signal._(value, debugLabel: debugLabel));
128+
return Rt.registerState(() => Signal._(value, debugLabel: debugLabel));
129129
}
130130

131131
/// Gets and/or sets to [value] like a function

packages/reactter/test/framework/rt_state_base_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class StateTest with RtState {
2929
}
3030

3131
factory StateTest() {
32-
return Rt.createState(() => StateTest._());
32+
return Rt.registerState(() => StateTest._());
3333
}
3434

3535
@override
@@ -41,7 +41,7 @@ void main() {
4141
test('should create a state object within the BindingZone', () {
4242
expect(() => CountTest(), throwsA(isA<AssertionError>()));
4343

44-
final countState = Rt.createState(() => CountTest());
44+
final countState = Rt.registerState(() => CountTest());
4545
expect(countState.debugLabel, 'CountTest');
4646

4747
final state = StateTest();
@@ -62,15 +62,15 @@ void main() {
6262
});
6363

6464
test('should update the state', () {
65-
final countState = Rt.createState(() => CountTest());
65+
final countState = Rt.registerState(() => CountTest());
6666
expect(countState.count, 0);
6767

6868
countState.count = 1;
6969
expect(countState.count, 1);
7070
});
7171

7272
test('should have debug info', () {
73-
final countState = Rt.createState(() => CountTest());
73+
final countState = Rt.registerState(() => CountTest());
7474
expect(countState.debugInfo, {"count": 0});
7575

7676
countState.count = 1;

packages/reactter/test/logger_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class StateTest with RtState {
66
StateTest._();
77

88
factory StateTest() {
9-
return Rt.createState(() => StateTest._());
9+
return Rt.registerState(() => StateTest._());
1010
}
1111

1212
@override

packages/reactter_devtools_extension/lib/src/bases/tree_list.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import 'dart:collection';
33
import 'package:flutter_reactter/reactter.dart';
44
import 'package:reactter_devtools_extension/src/bases/tree_node.dart';
55

6-
base class TreeList<E extends TreeNode<E>> extends LinkedList<E>
7-
with RtState {
6+
base class TreeList<E extends TreeNode<E>> extends LinkedList<E> with RtState {
87
final uMaxDepth = UseState(0);
98

109
TreeList._();
1110

12-
factory TreeList() => Rt.createState(() => TreeList<E>._());
11+
factory TreeList() => Rt.registerState(() => TreeList<E>._());
1312

1413
@override
1514
void add(E entry) => update(() => super.add(entry));

packages/reactter_devtools_extension/lib/src/nodes/dart/closure_node.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class ClosureNode extends AsyncNode {
1616
});
1717

1818
factory ClosureNode({required String key, required InstanceRef instanceRef}) {
19-
return Rt.createState(
19+
return Rt.registerState(
2020
() => ClosureNode.$(
2121
key: key,
2222
instanceRef: instanceRef,

0 commit comments

Comments
 (0)