chanjungskim
01/27/2023, 2:04 AM_orderData.value!!.checkoutResponse = newCheckoutResponse
_orderData.value = _orderData.value
gildor
01/27/2023, 3:43 AMchanjungskim
01/27/2023, 3:48 AM@Parcelize
@Keep
data class OrderData(
var multiCartBody: MultiCartAddRequestBody? = null,
var checkoutBody: CheckoutRequestBody? = null,
var checkoutResponseBody: CheckoutResponseBody? = null,
var spreadSheetData: SpreadSheetData? = null,
var finalPrice: Int = 0,
var membershipDiscount: Int = 0,
var promotionDiscount: Int = 0,
var totalProductPrice: Int = 0,
var membershipPrice: Int = 0,
) : Parcelable
And in an Activity, checkout API can be called multiple times. after canceling the order.
The part that I shared above is after receiving new checkout response.gildor
01/27/2023, 3:49 AMchanjungskim
01/27/2023, 3:51 AM_orderData.value = OrderData(newMultiCartBody, newCheckoutBody, ...)
??gildor
01/27/2023, 3:52 AMchanjungskim
01/27/2023, 3:52 AM_orderData.value = _orderData.value.copy( something )?
gildor
01/27/2023, 3:52 AMchanjungskim
01/27/2023, 3:52 AMgildor
01/27/2023, 3:53 AMclass OrderData(
val orderId: String
...
) {
val orderStatus: LiveData<OrderStatus>
/*potentially can be internal or not visible for consumer
fun updateOrderStatus(newStatus: OrderStatus) { ... }
}
do you think the class is fineIt’s just a data class, up to you what kind data have there, just make it immutable
chanjungskim
01/27/2023, 3:57 AMgildor
01/27/2023, 3:58 AMdata
from class, because it’s not really data class anymoreclass Order {
val orderData: OrderData // immutable part
} {
val orderStatus: LiveData<OrderData>
// any other reactive fields
}
And View(Activity or XML) observes its data inside that are LiveData, right?Yes, it forces consumer View to subscribe on updates of status if they want to access it
some edge cases if consuming code doing equality checkAn addition to this comment. It will break even standard LiveData operators like distingUntilChanged, because object always equals to itself: https://developer.android.com/reference/androidx/lifecycle/Transformations#(androidx.lifecycle.LiveData).distinctUntilChanged()
chanjungskim
01/27/2023, 4:40 AMnested reactive field
mean in your answer?gildor
01/27/2023, 5:57 AM