Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove private typealiases to fix generated documentation #554

Merged
merged 1 commit into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Remove private typealiases to fix generated documentation
  • Loading branch information
tonidero committed Jul 1, 2022
commit fd642491dcb90d673c5dffbbcf9e4b068d04fb59
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class Purchases internal constructor(
}

/**
* Make a purchase.
* Make a purchase upgrading from a previous sku.
* @param [activity] Current activity
* @param [storeProduct] The StoreProduct of the product you wish to purchase
* @param [upgradeInfo] The upgradeInfo you wish to upgrade from, containing the oldSku and the optional
Expand Down Expand Up @@ -407,7 +407,7 @@ class Purchases internal constructor(
}

/**
* Make a purchase.
* Make a purchase upgrading from a previous sku.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed these since otherwise these 2 methods with the same name had almost the same documentation.

* @param [activity] Current activity
* @param [packageToPurchase] The Package you wish to purchase
* @param [upgradeInfo] The upgradeInfo you wish to upgrade from, containing the oldSku and the optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.revenuecat.purchases.interfaces.ProductChangeListener
private typealias DeprecatedPurchaseCompletedFunction = (purchase: Purchase, purchaserInfo: PurchaserInfo) -> Unit
@Deprecated("Purchase replaced with StoreTransaction and PurchaserInfo with CustomerInfo")
private typealias DeprecatedProductChangeCompletedFunction = (purchase: Purchase?, purchaserInfo: PurchaserInfo) -> Unit
private typealias ErrorFunction = (error: PurchasesError) -> Unit
private typealias PurchaseErrorFunction = (error: PurchasesError, userCancelled: Boolean) -> Unit
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left these 2 here since we don't generate docs from these deprecated functions


@Deprecated("onCompleted Purchase changed with StoreTransaction")
internal fun deprecatedPurchaseCompletedListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@ import com.revenuecat.purchases.interfaces.ReceiveOfferingsCallback
import com.revenuecat.purchases.models.StoreProduct
import com.revenuecat.purchases.models.StoreTransaction

private typealias PurchaseCompletedFunction = (purchase: StoreTransaction, customerInfo: CustomerInfo) -> Unit
private typealias ProductChangeCompletedFunction = (purchase: StoreTransaction?, customerInfo: CustomerInfo) -> Unit
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we lose some info from not having the typealias name (for example, these 2 typealiases are almost identical). But I think we earn in making sure devs know exactly what the API looks like, so I think it's a good change overall

private typealias ReceiveOfferingsSuccessFunction = (offerings: Offerings) -> Unit
private typealias ReceiveCustomerInfoSuccessFunction = (customerInfo: CustomerInfo) -> Unit
private typealias ReceiveLogInSuccessFunction = (customerInfo: CustomerInfo, created: Boolean) -> Unit
internal typealias ErrorFunction = (error: PurchasesError) -> Unit
internal typealias PurchaseErrorFunction = (error: PurchasesError, userCancelled: Boolean) -> Unit

internal val ON_ERROR_STUB: ErrorFunction = {}
internal val ON_PURCHASE_ERROR_STUB: PurchaseErrorFunction = { _, _ -> }
internal val ON_ERROR_STUB: (error: PurchasesError) -> Unit = {}
internal val ON_PURCHASE_ERROR_STUB: (error: PurchasesError, userCancelled: Boolean) -> Unit = { _, _ -> }

internal fun purchaseCompletedCallback(
onSuccess: PurchaseCompletedFunction,
onError: PurchaseErrorFunction
onSuccess: (purchase: StoreTransaction, customerInfo: CustomerInfo) -> Unit,
onError: (error: PurchasesError, userCancelled: Boolean) -> Unit
) = object : PurchaseCallback {
override fun onCompleted(storeTransaction: StoreTransaction, customerInfo: CustomerInfo) {
onSuccess(storeTransaction, customerInfo)
Expand All @@ -35,8 +27,8 @@ internal fun purchaseCompletedCallback(
}

internal fun productChangeCompletedListener(
onSuccess: ProductChangeCompletedFunction,
onError: PurchaseErrorFunction
onSuccess: (purchase: StoreTransaction?, customerInfo: CustomerInfo) -> Unit,
onError: (error: PurchasesError, userCancelled: Boolean) -> Unit
) = object : ProductChangeCallback {
override fun onCompleted(purchase: StoreTransaction?, customerInfo: CustomerInfo) {
onSuccess(purchase, customerInfo)
Expand All @@ -49,7 +41,7 @@ internal fun productChangeCompletedListener(

internal fun getStoreProductsCallback(
onReceived: (storeProducts: List<StoreProduct>) -> Unit,
onError: ErrorFunction
onError: (error: PurchasesError) -> Unit
) = object : GetStoreProductsCallback {
override fun onReceived(storeProducts: List<StoreProduct>) {
onReceived(storeProducts)
Expand All @@ -61,8 +53,8 @@ internal fun getStoreProductsCallback(
}

internal fun receiveOfferingsCallback(
onSuccess: ReceiveOfferingsSuccessFunction,
onError: ErrorFunction
onSuccess: (offerings: Offerings) -> Unit,
onError: (error: PurchasesError) -> Unit
) = object : ReceiveOfferingsCallback {
override fun onReceived(offerings: Offerings) {
onSuccess(offerings)
Expand All @@ -74,8 +66,8 @@ internal fun receiveOfferingsCallback(
}

internal fun receiveCustomerInfoCallback(
onSuccess: ReceiveCustomerInfoSuccessFunction?,
onError: ErrorFunction?
onSuccess: (customerInfo: CustomerInfo) -> Unit?,
onError: (error: PurchasesError) -> Unit?
) = object : ReceiveCustomerInfoCallback {
override fun onReceived(customerInfo: CustomerInfo) {
onSuccess?.invoke(customerInfo)
Expand All @@ -87,8 +79,8 @@ internal fun receiveCustomerInfoCallback(
}

internal fun logInSuccessListener(
onSuccess: ReceiveLogInSuccessFunction?,
onError: ErrorFunction?
onSuccess: (customerInfo: CustomerInfo, created: Boolean) -> Unit?,
onError: (error: PurchasesError) -> Unit?
) = object : LogInCallback {
override fun onReceived(customerInfo: CustomerInfo, created: Boolean) {
onSuccess?.invoke(customerInfo, created)
Expand All @@ -112,8 +104,8 @@ internal fun logInSuccessListener(
*/
@Suppress("unused")
fun Purchases.getOfferingsWith(
onError: ErrorFunction = ON_ERROR_STUB,
onSuccess: ReceiveOfferingsSuccessFunction
onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB,
onSuccess: (offerings: Offerings) -> Unit
) {
getOfferings(receiveOfferingsCallback(onSuccess, onError))
}
Expand All @@ -128,14 +120,14 @@ fun Purchases.getOfferingsWith(
fun Purchases.purchaseProductWith(
activity: Activity,
storeProduct: StoreProduct,
onError: PurchaseErrorFunction = ON_PURCHASE_ERROR_STUB,
onSuccess: PurchaseCompletedFunction
onError: (error: PurchasesError, userCancelled: Boolean) -> Unit = ON_PURCHASE_ERROR_STUB,
onSuccess: (purchase: StoreTransaction, customerInfo: CustomerInfo) -> Unit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shoot I just realized we have an inconsistency on the order of the functions. Here we have onError first then onSuccess, which is on purpose so folks can omit the last parameter and do:

Purchases.purchaseProductWith(.....) { purchase, customerInfo ->

But other functions have the onError in last place 😮‍💨

Nothing to worry about now but wanted to mention it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh good catch! Yeah... I guess we might want to make it consistent on the next major... But probably we shouldn't change it here.

) {
purchaseProduct(activity, storeProduct, purchaseCompletedCallback(onSuccess, onError))
}

/**
* Make a purchase.
* Make a purchase upgrading from a previous sku.
* @param [activity] Current activity
* @param [storeProduct] The storeProduct of the product you wish to purchase
* @param [upgradeInfo] The upgradeInfo you wish to upgrade from, containing the oldSku and the optional prorationMode.
Expand All @@ -147,14 +139,14 @@ fun Purchases.purchaseProductWith(
activity: Activity,
storeProduct: StoreProduct,
upgradeInfo: UpgradeInfo,
onError: PurchaseErrorFunction = ON_PURCHASE_ERROR_STUB,
onSuccess: ProductChangeCompletedFunction
onError: (error: PurchasesError, userCancelled: Boolean) -> Unit = ON_PURCHASE_ERROR_STUB,
onSuccess: (purchase: StoreTransaction?, customerInfo: CustomerInfo) -> Unit
) {
purchaseProduct(activity, storeProduct, upgradeInfo, productChangeCompletedListener(onSuccess, onError))
}

/**
* Make a purchase.
* Make a purchase upgrading from a previous sku.
* @param [activity] Current activity
* @param [packageToPurchase] The Package you wish to purchase
* @param [upgradeInfo] The upgradeInfo you wish to upgrade from, containing the oldSku and the optional prorationMode.
Expand All @@ -166,8 +158,8 @@ fun Purchases.purchasePackageWith(
activity: Activity,
packageToPurchase: Package,
upgradeInfo: UpgradeInfo,
onError: PurchaseErrorFunction = ON_PURCHASE_ERROR_STUB,
onSuccess: ProductChangeCompletedFunction
onError: (error: PurchasesError, userCancelled: Boolean) -> Unit = ON_PURCHASE_ERROR_STUB,
onSuccess: (purchase: StoreTransaction?, customerInfo: CustomerInfo) -> Unit
) {
purchasePackage(activity, packageToPurchase, upgradeInfo, productChangeCompletedListener(onSuccess, onError))
}
Expand All @@ -182,8 +174,8 @@ fun Purchases.purchasePackageWith(
fun Purchases.purchasePackageWith(
activity: Activity,
packageToPurchase: Package,
onError: PurchaseErrorFunction = ON_PURCHASE_ERROR_STUB,
onSuccess: PurchaseCompletedFunction
onError: (error: PurchasesError, userCancelled: Boolean) -> Unit = ON_PURCHASE_ERROR_STUB,
onSuccess: (purchase: StoreTransaction, customerInfo: CustomerInfo) -> Unit
) {
purchasePackage(activity, packageToPurchase, purchaseCompletedCallback(onSuccess, onError))
}
Expand All @@ -202,8 +194,8 @@ fun Purchases.purchasePackageWith(
* @param [onError] Will be called after the call has completed with an error.
*/
fun Purchases.restorePurchasesWith(
onError: ErrorFunction = ON_ERROR_STUB,
onSuccess: ReceiveCustomerInfoSuccessFunction
onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB,
onSuccess: (customerInfo: CustomerInfo) -> Unit
) {
restorePurchases(receiveCustomerInfoCallback(onSuccess, onError))
}
Expand All @@ -218,8 +210,8 @@ fun Purchases.restorePurchasesWith(
@Suppress("unused")
fun Purchases.logInWith(
appUserID: String,
onError: ErrorFunction = ON_ERROR_STUB,
onSuccess: ReceiveLogInSuccessFunction
onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB,
onSuccess: (customerInfo: CustomerInfo, created: Boolean) -> Unit
) {
logIn(appUserID, logInSuccessListener(onSuccess, onError))
}
Expand All @@ -232,8 +224,8 @@ fun Purchases.logInWith(
*/
@Suppress("unused")
fun Purchases.logOutWith(
onError: ErrorFunction = ON_ERROR_STUB,
onSuccess: ReceiveCustomerInfoSuccessFunction
onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB,
onSuccess: (customerInfo: CustomerInfo) -> Unit
) {
logOut(receiveCustomerInfoCallback(onSuccess, onError))
}
Expand All @@ -246,8 +238,8 @@ fun Purchases.logOutWith(
*/
@Suppress("unused")
fun Purchases.getCustomerInfoWith(
onError: ErrorFunction = ON_ERROR_STUB,
onSuccess: ReceiveCustomerInfoSuccessFunction
onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB,
onSuccess: (customerInfo: CustomerInfo) -> Unit
) {
getCustomerInfo(receiveCustomerInfoCallback(onSuccess, onError))
}
Expand All @@ -262,8 +254,8 @@ fun Purchases.getCustomerInfoWith(
@Suppress("unused")
fun Purchases.getCustomerInfoWith(
fetchPolicy: CacheFetchPolicy,
onError: ErrorFunction = ON_ERROR_STUB,
onSuccess: ReceiveCustomerInfoSuccessFunction
onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB,
onSuccess: (customerInfo: CustomerInfo) -> Unit
) {
getCustomerInfo(fetchPolicy, receiveCustomerInfoCallback(onSuccess, onError))
}
Expand All @@ -276,7 +268,7 @@ fun Purchases.getCustomerInfoWith(
@Suppress("unused")
fun Purchases.getSubscriptionSkusWith(
skus: List<String>,
onError: ErrorFunction = ON_ERROR_STUB,
onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB,
onReceiveSkus: (storeProducts: List<StoreProduct>) -> Unit
) {
getSubscriptionSkus(skus, getStoreProductsCallback(onReceiveSkus, onError))
Expand All @@ -290,7 +282,7 @@ fun Purchases.getSubscriptionSkusWith(
@Suppress("unused")
fun Purchases.getNonSubscriptionSkusWith(
skus: List<String>,
onError: ErrorFunction,
onError: (error: PurchasesError) -> Unit,
onReceiveSkus: (storeProducts: List<StoreProduct>) -> Unit
) {
getNonSubscriptionSkus(skus, getStoreProductsCallback(onReceiveSkus, onError))
Expand Down