mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 06:14:55 -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
|
||||
import { ReplaySubject, Observable } from "rxjs";
|
||||
import FoodItemRecord, { createFoodItem } from "../records/FoodItemRecord";
|
||||
import { setById } from "../helpers/ImmutableHelpers";
|
||||
import { Map } from "immutable";
|
||||
import location$ from "./LocationStream";
|
||||
import { getFoodItems, type FoodItemsForLocation } from "../apis/FoodItemsApi";
|
||||
import Filter$ from "./FilterStream";
|
||||
import Quantity$ from "./QuantityStream";
|
||||
import type { QuantityFragment } from "../constants/QuantityConstants";
|
||||
import { type ImageFragment } from "../records/ImageRecord";
|
||||
import Image$ from "./ImagesStream";
|
||||
import { ReplaySubject, Observable } from 'rxjs';
|
||||
import FoodItemRecord, { createFoodItem, type FoodItem } from '../records/FoodItemRecord';
|
||||
import { setById } from '../helpers/ImmutableHelpers';
|
||||
import { Map, type Record } from 'immutable';
|
||||
import location$ from './LocationStream';
|
||||
import { getFoodItems, type FoodItemsForLocation } from '../apis/FoodItemsApi';
|
||||
import Filter$ from './FilterStream';
|
||||
import Quantity$ from './QuantityStream';
|
||||
import type { QuantityFragment } from '../constants/QuantityConstants';
|
||||
import { type ImageFragment } from '../records/ImageRecord';
|
||||
import Image$ from './ImagesStream';
|
||||
|
||||
const foodItemSubject: ReplaySubject<FoodItemRecord> = new ReplaySubject();
|
||||
|
||||
|
|
@ -49,26 +49,20 @@ export default fetchedFoodItems$
|
|||
})
|
||||
.combineLatest(
|
||||
Quantity$,
|
||||
(foodItems: ?Map<string, FoodItemRecord>, quantitiesFromStream: Map<string, QuantityFragment>) => {
|
||||
(
|
||||
foodItems: ?Map<string, Record<FoodItem>>,
|
||||
quantitiesFromStream: Map<string, QuantityFragment>
|
||||
) => {
|
||||
if (foodItems) {
|
||||
return foodItems.mergeDeepWith(
|
||||
(foodItem, foodItemQuantities) => foodItem.merge(foodItemQuantities),
|
||||
quantitiesFromStream
|
||||
);
|
||||
return foodItems.mergeDeep(quantitiesFromStream);
|
||||
}
|
||||
}
|
||||
)
|
||||
.combineLatest(
|
||||
Image$,
|
||||
(foodItems: ?Map<string, FoodItemRecord>, latestFromImages$: Map<string, ImageFragment>) => {
|
||||
if (foodItems) {
|
||||
return foodItems.mergeDeepWith(
|
||||
// $FlowFixMe
|
||||
(foodItem: FoodItemRecord, imageFragment: ImageFragment) => {
|
||||
return foodItem.set("images", imageFragment.images);
|
||||
},
|
||||
latestFromImages$
|
||||
);
|
||||
}
|
||||
(foodItems: ?Map<string, Record<FoodItem>>, latestFromImages$: Map<String, ImageFragment>) => {
|
||||
return latestFromImages$.reduce((foodItemMap, { id, images }) => {
|
||||
return foodItemMap.setIn([id, 'images'], images);
|
||||
}, foodItems || Map());
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue