updateItem<T> function

ThunkAction<SwipeFeedState<T>> updateItem<T>(
  1. T item,
  2. String id,
  3. String objectKey(
    1. T
    )
)

updates an item in the feed

Implementation

ThunkAction<SwipeFeedState<T>> updateItem<T>(T item, String id, String Function(T) objectKey){
  return (Store<SwipeFeedState<T>> store) async {
    List<Tuple2<T?, Store<SwipeFeedCardState>>> items = store.state.items;
    if(items.isNotEmpty && items[0].item1 != null && id == objectKey(items[0].item1!)){
      items.remove(items[0]);
      store.dispatch(SetItemsEvent(items));
      List<Tuple2<T?, Store<SwipeFeedCardState>>> addNewItem = [Tuple2(item, SwipeFeedCardState.tower(SwipeCardShowState())), ...store.state.items];
      store.dispatch(SetItemsEvent(addNewItem));
    }
  };
}