Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 20a84a3

Browse files
committed
docs: update examples
1 parent e4390e2 commit 20a84a3

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ This repository holds a set of helpers that are aiming to provide:
2828
This is an example of how to use the `*rxLet` directive to bind an Observable value to the template. In this example, the component defines a property `time$`, which is an Observable that emits a value every second using the `timer` operator. The emitted values are mapped to the current time string using the `map` operator which is then displayed in the template using `*rxLet`.
2929

3030
```ts
31+
import { RxLet } from '@rx-angular/template/let';
32+
3133
@Component({
3234
selector: 'app-time',
3335
standalone: true,
34-
imports: [LetDirective],
36+
imports: [RxLet],
3537
template: `
3638
<ng-container *rxLet="time$; let value">
3739
{{ value }}
@@ -47,27 +49,29 @@ To learn more about @rx-angular/template and its capabilities, check out the off
4749

4850
### Using `@rx-angular/state`
4951

50-
In this example, we're creating a fully reactive counter component. We use the `rxState` functional API to create the state. We also define two actions to increment and decrement the count and use the `connect` function to update the state in response to these actions. Finally, we use the `select` function to display the count property of the state in the template.
52+
In this example, we're creating a fully reactive counter component. We use `rxState` to manage the component's state, `rxActions` to define structured actions for state updates (specifically `increment` and `decrement`), and `rxEffects` to trigger side-effects when state changes occur. These mechanisms collectively enable efficient state management, action handling, and side-effect execution, resulting in a responsive and well-structured counter component.
5153

5254
```ts
55+
import { rxState } from '@rx-angular/state';
56+
import { rxEffects } from '@rx-angular/state/effects';
57+
import { rxActions } from '@rx-angular/state/actions';
58+
import { RxPush } from '@rx-angular/template/push';
59+
5360
@Component({
5461
selector: 'app-counter',
5562
standalone: true,
56-
imports: [PushPipe],
63+
imports: [RxPush],
5764
template: `
5865
<p>Count: {{ count$ | push }}</p>
5966
<button (click)="actions.increment()">Increment</button>
6067
<button (click)="actions.decrement()">Decrement</button>
6168
`,
62-
providers: [RxActionFactory],
6369
})
6470
export class CounterComponent {
65-
private readonly actions = inject<
66-
RxActionFactory<{
67-
increment: void;
68-
decrement: void;
69-
}>
70-
>(RxActionFactory).create();
71+
readonly actions = rxActions<{
72+
increment: void;
73+
decrement: void;
74+
}>();
7175

7276
private readonly state = rxState<{
7377
count: number;
@@ -82,10 +86,16 @@ export class CounterComponent {
8286
});
8387

8488
readonly count$ = this.state.select('count');
89+
90+
constructor() {
91+
rxEffects(({ register }) => {
92+
register(this.count$, (count) => console.log(`Count changed: ${count}`));
93+
});
94+
}
8595
}
8696
```
8797

88-
To learn more about @rx-angular/state and its capabilities, check out the official documentation at [https://rx-angular.io/docs/state](https://rx-angular.io/docs/state).
98+
To learn more about `@rx-angular/state` and its capabilities, check out the official documentation at [https://rx-angular.io/docs/state](https://rx-angular.io/docs/state).
8999

90100
## Used by
91101

0 commit comments

Comments
 (0)