Skip to content

Commit 676273f

Browse files
committed
docs: Add API title to core concepts documentation and add a dependency injection example.
1 parent 3a3fc6a commit 676273f

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

website/src/content/docs/core_concepts/dependency_injection.mdx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Dependency injection offers several benefits.
1717
- **Inversion of Control**: It adheres to the principle of inversion of control, where the responsibility for object creation and management is delegated to Reactter. This results in improved code _modularity_, _reusability_, and _testability_.
1818
- **Simplified Code**: By offloading the responsibility of creating dependencies from individual classes, dependency injection simplifies code, allowing classes to focus more on their core functionality.
1919

20+
## API
21+
2022
Reactter provides the following dependencies injection mechanisms:
2123

2224
- Hooks
@@ -243,11 +245,30 @@ void main() async {
243245
print('Count: ${counter?.count ?? 'Counter instance not found'}');
244246
}
245247
```
246-
In this case, the countdown will work as before, but when trying to get the <HT>`Counter`</HT> instance to print itsvalue,
248+
In this case, the countdown will work as before, but when trying to get the <HT>`Counter`</HT> instance to print its value,
247249
the ouput will be _“Counter instance not found”_.
248250
This occurs because <HT>`Counter`</HT> was registered as <HE>`DependencyMode.builder`</HE>(the default mode),
249251
so when it was deleted at the end of the countdown its registration was also deleted.
250-
If we want to get the <HT>`Counter`</HT> instance to print its value, we need to register using the <HE>`DependencyMode.singleton`</HE> mode.
252+
If we want to get the <HT>`Counter`</HT> instance to print its value, we need to register using the <HE>`DependencyMode.singleton`</HE> mode, looking like this:
253+
254+
```dart title="main.dart" {7} collapse={8-15} "Rt.register" "Rt.create" "Rt.get" "DependencyMode.singleton" /counter(?!\\.)/ "counter?.count" /Counter(?!\u0060)(?! )/ /Countdown(?!\u0060)/ /(countdown) =/ "countdown.run"
255+
import 'package:reactter/reactter.dart';
256+
import 'countdown.dart';
257+
import 'counter.dart';
258+
259+
void main() async {
260+
// Register the `Counter` class as singleton mode with an initial value of 20
261+
Rt.register(() => Counter(20), mode: DependencyMode.singleton);
262+
// Create an instance of the `Countdown` class
263+
final countdown = Rt.create(() => Countdown())!;
264+
// Start the countdown
265+
await countdown.run();
266+
// Get the instance of the `Counter` class
267+
final counter = Rt.get<Counter>();
268+
// Try to print the current count value
269+
print('Count: ${counter?.count ?? 'Counter instance not found'}');
270+
}
271+
```
251272

252273
Let's now delve into the **modes** of dependency registration.
253274

website/src/content/docs/core_concepts/event_handler.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and coordination between various components within the application.
1111
Designed to ensure efficient state management and dependency injection,
1212
fostering a cohesive ecosystem where different parts of the application can interact harmoniously.
1313

14+
## API
15+
1416
Reactter offers the following event handler mechanisms:
1517

1618
- Hooks

website/src/content/docs/core_concepts/hooks.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import UseTextInputCode from '@/examples/custom_hook/lib/use_text_input.dart?raw
2020

2121
Hooks are classes with the ability to use states and manage side effects. They are a fundamental concept in Reactter and are used to encapsulate logic that can be reused across the application.
2222

23+
## API
24+
2325
Reactter provider some hooks to manage the state and side effects of the application, which are:
2426

2527
- <HT>[`UseState`](/reactter/hooks/use_state)</HT>

website/src/content/docs/core_concepts/rendering_control.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import counterMainCode from '@/examples/counter/lib/main.dart?raw';
2020

2121
In Flutter, efficient rendering control is essential for crafting high-performance, responsive, and scalable applications.
2222
Reactter provides a way to easily control the rendering of components in the widget tree behavior effortlessly, using the _**flutter_reactter**_ package.
23+
24+
## API
25+
2326
This package provides a collection of classes, widgets and some methods:
2427

2528
- Classes
@@ -45,7 +48,7 @@ The rendering control in Reactter is based on two core concepts of Flutter:
4548
- **InheritedWidget**: This powerful mechanism efficiently shares data across the widget tree.
4649
Reactter extends this capability with the <HT>`RtProvider`</HT> widget, which stores dependencies using the dependency injection system.
4750
This allows descendant widgets to access these dependencies as needed.
48-
- **BuildContext Methods**: These methods facilitate dependency access and rendering control within the widget tree.
51+
- **BuildContext Extensions**: These methods facilitate dependency access and rendering control within the widget tree.
4952
Reactter widgets like <HT>`RtConsumer`</HT>, <HT>`RtSelector`</HT>, and <HT>`RtComponent`</HT> use these methods to observe dependencies or states.
5053
Whenever the dependency or any observed state undergoes a change, these widgets promptly trigger the rebuilding of the widget tree to reflect the updated state.
5154

website/src/content/docs/core_concepts/state_management.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import StateMethods from '@/content/docs/shareds/state_methods.mdx';
1010
State management is a critical aspect of any application.
1111
It allows you to manage the state of your application, and facilitates seamless tracking and handling of changes to it.
1212

13+
## API
14+
1315
Reactter provides a variety of mechanisms for state management, including classes, hooks, and methods:
1416

1517
- Classes
@@ -33,7 +35,7 @@ Reactter provides a variety of mechanisms for state management, including classe
3335
Reactter's state management system is based on the concept of _reactivity_.
3436
Contrary to the prevailing notion that implementing reactive programming in Dart can be challenging,
3537
Reactter greatly simplifies this process.
36-
To dive into the concept, let's start by exploring what constitutes a state in Rt.
38+
To dive into the concept, let's start by exploring what constitutes a state in Reactter.
3739

3840
### State
3941

website/src/content/docs/getting_started.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ title: Getting started
33
description: A step-by-step guide to installing and how to use Reactter.
44
---
55

6-
import { Icon } from "astro-icon/components";
76
import { Code } from "@astrojs/starlight/components";
87

98
import reactterVersion from "@/data/reactter_version";

0 commit comments

Comments
 (0)