mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 07:54:57 -06:00
fix crash when merging images into food items
This commit is contained in:
parent
c212cf1d88
commit
07aa936338
1 changed files with 20 additions and 26 deletions
|
|
@ -1,15 +1,15 @@
|
||||||
//@flow
|
//@flow
|
||||||
import { ReplaySubject, Observable } from "rxjs";
|
import { ReplaySubject, Observable } from 'rxjs';
|
||||||
import FoodItemRecord, { createFoodItem } from "../records/FoodItemRecord";
|
import FoodItemRecord, { createFoodItem, type FoodItem } from '../records/FoodItemRecord';
|
||||||
import { setById } from "../helpers/ImmutableHelpers";
|
import { setById } from '../helpers/ImmutableHelpers';
|
||||||
import { Map } from "immutable";
|
import { Map, type Record } from 'immutable';
|
||||||
import location$ from "./LocationStream";
|
import location$ from './LocationStream';
|
||||||
import { getFoodItems, type FoodItemsForLocation } from "../apis/FoodItemsApi";
|
import { getFoodItems, type FoodItemsForLocation } from '../apis/FoodItemsApi';
|
||||||
import Filter$ from "./FilterStream";
|
import Filter$ from './FilterStream';
|
||||||
import Quantity$ from "./QuantityStream";
|
import Quantity$ from './QuantityStream';
|
||||||
import type { QuantityFragment } from "../constants/QuantityConstants";
|
import type { QuantityFragment } from '../constants/QuantityConstants';
|
||||||
import { type ImageFragment } from "../records/ImageRecord";
|
import { type ImageFragment } from '../records/ImageRecord';
|
||||||
import Image$ from "./ImagesStream";
|
import Image$ from './ImagesStream';
|
||||||
|
|
||||||
const foodItemSubject: ReplaySubject<FoodItemRecord> = new ReplaySubject();
|
const foodItemSubject: ReplaySubject<FoodItemRecord> = new ReplaySubject();
|
||||||
|
|
||||||
|
|
@ -49,26 +49,20 @@ export default fetchedFoodItems$
|
||||||
})
|
})
|
||||||
.combineLatest(
|
.combineLatest(
|
||||||
Quantity$,
|
Quantity$,
|
||||||
(foodItems: ?Map<string, FoodItemRecord>, quantitiesFromStream: Map<string, QuantityFragment>) => {
|
(
|
||||||
|
foodItems: ?Map<string, Record<FoodItem>>,
|
||||||
|
quantitiesFromStream: Map<string, QuantityFragment>
|
||||||
|
) => {
|
||||||
if (foodItems) {
|
if (foodItems) {
|
||||||
return foodItems.mergeDeepWith(
|
return foodItems.mergeDeep(quantitiesFromStream);
|
||||||
(foodItem, foodItemQuantities) => foodItem.merge(foodItemQuantities),
|
|
||||||
quantitiesFromStream
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.combineLatest(
|
.combineLatest(
|
||||||
Image$,
|
Image$,
|
||||||
(foodItems: ?Map<string, FoodItemRecord>, latestFromImages$: Map<string, ImageFragment>) => {
|
(foodItems: ?Map<string, Record<FoodItem>>, latestFromImages$: Map<String, ImageFragment>) => {
|
||||||
if (foodItems) {
|
return latestFromImages$.reduce((foodItemMap, { id, images }) => {
|
||||||
return foodItems.mergeDeepWith(
|
return foodItemMap.setIn([id, 'images'], images);
|
||||||
// $FlowFixMe
|
}, foodItems || Map());
|
||||||
(foodItem: FoodItemRecord, imageFragment: ImageFragment) => {
|
|
||||||
return foodItem.set("images", imageFragment.images);
|
|
||||||
},
|
|
||||||
latestFromImages$
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue