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

Skip to content

Commit 163e81b

Browse files
authored
Update Readme.md
1 parent b7a02bd commit 163e81b

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

libs/state/selections/docs/Readme.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ One time they are displayed in a sorted order, the other time only filtered subs
4646
4747
![Selections (2)](https://user-images.githubusercontent.com/10064416/152422803-bfd07ab2-0a6f-4521-836e-b71677e11923.png)
4848

49-
50-
5149
As this process contains a lot of gotchas and possible pitfalls in terms of memory usage and performance this small helper library was created.
5250

5351
# Benefits
@@ -77,8 +75,52 @@ In most cases it's best to go with solving problems on the early subscriber side
7775
![Selections (4)](https://user-images.githubusercontent.com/10064416/152422883-0b5f6006-7929-4520-b0b2-79eb61e4eb08.png)
7876

7977

78+
## Advanced derivation architecture
79+
80+
**The problem**
81+
82+
We have the following state sources to manage:
83+
- the list of products received form global state - `Product[]`
84+
- the title of the list including it's number of children computen in the component class - `string`
85+
- the sort direction triggered over a UI element click - `boolean`
86+
87+
A setup of the compoents class based on `RxState` could look like this:
88+
89+
```typescript
90+
@Component({
91+
selector: 'app-problem',
92+
template: `
93+
<ng-container>
94+
<h1>{{}}</h1>
95+
</ng-container>
96+
`,
97+
providers: [RxState],
98+
})
99+
export class ProblemComponent {
100+
101+
constructor(private globalState: GlobalState, private state: RxState<Model>) {
102+
this.state.set(title: 'My list')
103+
this.state.connect('products', this.globalState.products$);
104+
105+
}
106+
107+
toggleSort() {
108+
this.state.set('sort', ({sort}) => !sort))
109+
}
110+
}
111+
112+
```
113+
114+
In a components template we want to render the the UI for the above explained view model `SelectionScreen1`.
115+
116+
```typescript
117+
interface SelectionScreen1 {
118+
title: string;
119+
sortDirection: 'asc' | 'desc' | 'none';
120+
list: Array<{ id: number }>
121+
}
122+
```
80123

81-
## Advanced derivations architecture
82124

83125
![Selections (6)](https://user-images.githubusercontent.com/10064416/152422999-db8260f0-69e1-4d99-b6ac-b2b1d043b4b7.png)
84126

0 commit comments

Comments
 (0)