Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. @Effect() route$ = actions$
  2. .ofType(ACTION_A)
  3. .switchMap(() => this._store.let(getCapabilities)
  4. .filter(capabilities => !isOutOfDate(capabilities))
  5. .take(1)
  6. )
  7. .map( do some stuff );
  8.  
  9. // Selector function that causes excess observable emits
  10. export const getCapabilities =
  11. compose(fromLocations.currentLocationLookup(fromLocations.getCapabilities), fromRoot.getLocations);
  12.  
  13. // Selector function works as expected
  14. export const getCapabilitiesWorking = function (state$: Observable<AppState>): Observable<Capability> {
  15. return state$
  16. .let(fromRoot.getLocations)
  17. .map(l => l.capabilitiesByLocation[l.currentId]);
  18. };
  19.  
  20. // fromLocations
  21. // -------------
  22.  
  23. export function getCapabilities(state$: Observable<LocationsState>): Observable<{ [id: string]: Capability }> {
  24. return state$.map(s => s.capabilitiesByLocation);
  25. }
  26.  
  27. // Find the value in 'collection' corresponding to the current location
  28. export function currentLocationLookup<T>(
  29. collection: (state$: Observable<LocationsState>) => Observable<{ [id: string]: T }>
  30. ): (state$: Observable<LocationsState>) => Observable<T> {
  31. return (state$: Observable<LocationsState>): Observable<T> => {
  32. return Observable.combineLatest(
  33. state$.let(getCurrentLocation),
  34. state$.let(collection),
  35. (locId, map) => map[locId]
  36. );
  37. };
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement