File tree Expand file tree Collapse file tree
feature-luggage/luggage-overview Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import {
2+ linkedSignal ,
3+ Resource ,
4+ resourceFromSnapshots ,
5+ ResourceSnapshot ,
6+ Signal ,
7+ } from '@angular/core' ;
8+
9+ import { Luggage } from './luggage' ;
10+
11+ export function withMinWeight (
12+ input : Resource < Luggage [ ] > ,
13+ minWeight : Signal < number > ,
14+ ) : Resource < Luggage [ ] > {
15+ const derived = linkedSignal <
16+ { snap : ResourceSnapshot < Luggage [ ] > ; min : number } ,
17+ ResourceSnapshot < Luggage [ ] >
18+ > ( {
19+ source : ( ) => ( {
20+ snap : input . snapshot ( ) ,
21+ min : minWeight ( ) ,
22+ } ) ,
23+ computation : ( { snap, min } ) => {
24+ if ( snap . status === 'resolved' ) {
25+ return {
26+ ...snap ,
27+ value : snap . value . filter ( ( item ) => item . weight >= min ) ,
28+ } ;
29+ }
30+ return snap ;
31+ } ,
32+ } ) ;
33+
34+ return resourceFromSnapshots ( derived ) ;
35+ }
Original file line number Diff line number Diff line change 11import { inject , Service , signal } from '@angular/core' ;
22
3+ import { withPreviousValue } from '../../../shared/util-common/with-previous-value' ;
34import { LuggageClient } from '../../data/luggage-client' ;
45
56@Service ( { autoProvided : false } )
67export class SimpleLuggageStore {
78 private luggageClient = inject ( LuggageClient ) ;
89
9- private readonly luggageResource = this . luggageClient . findLuggage ( ) ;
10+ private readonly luggageResource = withPreviousValue (
11+ this . luggageClient . findLuggage ( ) ,
12+ ) ;
1013 readonly luggage = this . luggageResource . value ;
1114 readonly isLoading = this . luggageResource . isLoading ;
1215 readonly error = this . luggageResource . error ;
You can’t perform that action at this time.
0 commit comments