@@ -46,8 +46,6 @@ One time they are displayed in a sorted order, the other time only filtered subs
46
46
47
47
![ Selections (2)] ( https://user-images.githubusercontent.com/10064416/152422803-bfd07ab2-0a6f-4521-836e-b71677e11923.png )
48
48
49
-
50
-
51
49
As this process contains a lot of gotchas and possible pitfalls in terms of memory usage and performance this small helper library was created.
52
50
53
51
# Benefits
@@ -77,8 +75,52 @@ In most cases it's best to go with solving problems on the early subscriber side
77
75
![ Selections (4)] ( https://user-images.githubusercontent.com/10064416/152422883-0b5f6006-7929-4520-b0b2-79eb61e4eb08.png )
78
76
79
77
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
+ ```
80
123
81
- ## Advanced derivations architecture
82
124
83
125
![ Selections (6)] ( https://user-images.githubusercontent.com/10064416/152422999-db8260f0-69e1-4d99-b6ac-b2b1d043b4b7.png )
84
126
0 commit comments