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

Skip to content

Commit 98f7664

Browse files
committed
docs(state): improve API section
1 parent 02e8546 commit 98f7664

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
sidebar_label: Functional Creation (NEW)
3+
sidebar_position: 1
4+
title: Functional Creation
5+
---
6+
7+
## Overview
8+
9+
The new Functional Creation API lets you create and configure `RxState` in only one place.
10+
11+
## Example
12+
13+
```typescript
14+
import { RxFor } from '@rx-angular/template/for';
15+
16+
@Component({
17+
template: `<movie *rxFor="let movie of movies$" [movie]="movie" />`,
18+
imports: [RxFor],
19+
})
20+
export class MovieListComponent {
21+
private state = rxState<{ movies: Movie[] }>(({ set }) => {
22+
// set initial state
23+
set({ movies: [] });
24+
});
25+
26+
// select a property for the template to consume
27+
movies$ = this.state.select('movies');
28+
}
29+
```
30+
31+
## Signature
32+
33+
The functional creation API is based on the class-based `RxState` API, more details about the signature [here](./rx-state).
34+
35+
```typescript
36+
import { RxState as LegacyState } from '@rx-angular/state';
37+
38+
export type RxState<T extends object> = Pick<
39+
LegacyState<T>,
40+
'get' | 'select' | 'connect' | 'set' | '$' | 'setAccumulator'
41+
>;
42+
43+
export type RxStateSetupFn<State extends object> = (
44+
rxState: Pick<RxState<State>, 'connect' | 'set' | 'setAccumulator'>
45+
) => void;
46+
47+
export function rxState<State extends object>(
48+
setupFn?: RxStateSetupFn<State>
49+
): RxState<State>;
50+
```

apps/docs/docs/state/api/rx-state.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
sidebar_label: RxState
3-
sidebar_position: 1
3+
sidebar_position: 2
44
title: RxState
55
# Moved from libs/state/api/
66
---
77

88
## Overview
99

10-
RxState is a light-weight reactive state management service for managing local state in angular.
10+
`RxState` is a light-weight reactive state management service for managing local state in Angular.
1111

12-
_Example_
12+
## Example
1313

1414
```typescript
1515
Component({

0 commit comments

Comments
 (0)