@@ -116,15 +116,15 @@ In most cases it's best to go with solving problems on the early subscriber side
116
116
117
117
` select ` is the stand-alone version of the ` RxState#select ` top level method. It helps to create default selection's from a changing state source.
118
118
119
- ``` typescritp
119
+ ``` typescript
120
120
// emissions:
121
121
// 0. - no emission ever happened
122
122
// 1. {a: 1} - incomplete state leads to `?` pollution in the template
123
123
// 2. {a: 1, b: 'a'} - render relevant emission
124
- // 2. {a: 1, b: 'a'} - same instance emisssion
124
+ // 2. {a: 1, b: 'a'} - same instance emission
125
125
// 3. {a: 1, b: 'a', c: true} - render irrelevant change
126
126
// 4. {a: 1, b: 'b', c: true} - render relevant emission
127
- const model$: Observable<Partial<{a: number, b: string, c: boolean}>>;
127
+ const model$: Observable <Partial <{ a: number ; b: string ; c: boolean }>>;
128
128
```
129
129
130
130
** Problem**
@@ -140,7 +140,7 @@ B: {{(model$ | push)?.b}}
140
140
141
141
### single property short hand
142
142
143
- ``` typescritp
143
+ ``` typescript
144
144
const vm$ = model$ .pipe (select (' b' ));
145
145
```
146
146
@@ -154,8 +154,8 @@ B: {{(model$ | push).b}}
154
154
155
155
### single operators
156
156
157
- ``` typescritp
158
- const vm$: Observable<> = model$.pipe(select(map(({b }) => b === 'a')));
157
+ ``` typescript
158
+ const vm$: Observable <> = model$ .pipe (select (map (({ b }) => b === ' a' )));
159
159
```
160
160
161
161
``` html
@@ -168,21 +168,21 @@ B: {{(model$ | push).b}}
168
168
169
169
## selectSlice
170
170
171
- ## smosh
172
-
173
171
## distinctUntilSomeChanges
174
172
173
+ ## stateful
174
+
175
175
# Advanced derivation architecture
176
176
177
177
** The problem**
178
178
179
179
We have the following state sources to manage:
180
180
181
181
- the list of products received form global state - ` Product[] `
182
- - the title of the list including it's number of children computen in the component class - ` string `
182
+ - the title of the list including it's number of children computed in the component class - ` string `
183
183
- the sort direction triggered over a UI element click - ` boolean `
184
184
185
- A setup of the compoents class based on ` RxState ` could look like this:
185
+ A setup of the components class based on ` RxState ` could look like this:
186
186
187
187
``` typescript
188
188
@Component ({
@@ -226,7 +226,6 @@ interface SelectionScreen1 {
226
226
A common implementations looks like this:
227
227
228
228
``` typescript
229
- // template removed for brevity
230
229
export class ProblemComponent {
231
230
private sortedList$ = this .state .select (
232
231
selectSlice ([' sortDirection' , ' list' ]),
@@ -240,7 +239,7 @@ export class ProblemComponent {
240
239
selectSlice ([' title' , ' sortedList' , ' sortDirection' ])
241
240
);
242
241
243
- // ❌ BAD: modle viewmodel mix up 👇
242
+ // ❌ BAD: model and view model mix up 👇
244
243
constructor (
245
244
private globalState : GlobalState ,
246
245
private state : RxState <Model & Pick <ViewModel , ' sortedList' >>
@@ -257,41 +256,20 @@ export class ProblemComponent {
257
256
258
257
![ Selections (6)] ( https://user-images.githubusercontent.com/10064416/152422999-db8260f0-69e1-4d99-b6ac-b2b1d043b4b7.png )
259
258
260
- By removing the sorted list form the state and moving it into the selection
261
- we can clean up the state's typing and have a nice separation of which data is owned by the component (model) and which data is owned by the template (view model)
259
+ By removing the sorted list form the state and moving it into the selection we can clean up the state's typing and have a nice separation of which data is owned by the component (model) and which data is owned by the template (view model)
262
260
263
261
``` typescript
264
- // template removed for brevity
265
262
export class ProblemComponent {
266
263
private sortedSlice$ = this .state .select (
267
- selectSlice ( [' sortDirection' , ' list' ]) ,
268
- map ( ({ list , sortDirection }) => {
264
+ [' sortDirection' , ' list' ],
265
+ ({ list , sortDirection }) => {
269
266
// sort `list` by `sortDirection` to `sortedList` here
270
267
return { sortDirection , sortedList };
271
- })
268
+ }
272
269
);
273
270
274
271
// ✔ GOOD: Derive view model from model 👇
275
- viewModel$ = smosh ({ title: this .state .select (' title' ) }, this .sortedSlice$ );
276
-
277
- // target API
278
- viewModel$ = smosh (
279
- {
280
- prop1: ' prop1' , // string
281
- prop2: prop1$ , // Observable<string>
282
- },
283
- slice1$ , // Observable<{prop3: 3}>
284
- slice2$ // Observable<{prop4: 'four'}>,
285
- // durationSelector$ (optional)
286
- );
287
-
288
- // ✔ GOOD: Derive view model from model 👇
289
- viewModel$ = smosh (
290
- {
291
- title: this .state .select (' title' ),
292
- },
293
- [this .sortedSlice$ ]
294
- );
272
+ vm$ = // what to promote here as smosh isn't part of RxA?
295
273
296
274
constructor (private globalState : GlobalState , private state : RxState <Model >) {
297
275
// ...
0 commit comments