Adds EnumDeserializerWithDefault and SealedDeserializerWithDefault#2345
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2345 +/- ##
==========================================
- Coverage 80.15% 79.93% -0.23%
==========================================
Files 282 284 +2
Lines 10023 10051 +28
Branches 1418 1422 +4
==========================================
Hits 8034 8034
- Misses 1377 1405 +28
Partials 612 612 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ajpallares
left a comment
There was a problem hiding this comment.
I think it makes sense, but I'll leave approval to someone who knows Kotlin better
| internal abstract class SealedDeserializerWithDefault<T : Any>( | ||
| private val serialName: String, | ||
| private val serializerByType: Map<String, () -> KSerializer<out T>>, | ||
| private val defaultValue: () -> T, |
There was a problem hiding this comment.
This is an optimization to only lazily compute the defaultValue when needed, right?
There was a problem hiding this comment.
I guess that a sealed class default might have properties that also need to be initialized... I think this way we allow that?
There was a problem hiding this comment.
Yea, it's very likely premature, but also practically free. I figured this abstract class doesn't know what the default value of its implementation will be, and this avoids any computation as well as object instantiation to when it is needed. Otherwise all default values will be instantiated right away.
tonidero
left a comment
There was a problem hiding this comment.
Nice! I haven't checked the usage yet, but these make sense to me!
| defaultValue = defaultValue, | ||
| ) | ||
|
|
||
| private val enumName = defaultValue.javaClass.simpleName |
There was a problem hiding this comment.
I guess if/when we fix minification in our SDKs, we should remember to keep the names of these enums... But we should be ok for now 👍
There was a problem hiding this comment.
That's a very good point!
There was a problem hiding this comment.
Actually, it's only used in the SerialDescriptor, so I think that should be fine. Still good to double check when we minify.
| internal abstract class SealedDeserializerWithDefault<T : Any>( | ||
| private val serialName: String, | ||
| private val serializerByType: Map<String, () -> KSerializer<out T>>, | ||
| private val defaultValue: () -> T, |
There was a problem hiding this comment.
I guess that a sealed class default might have properties that also need to be initialized... I think this way we allow that?
📸 Snapshot Test2 modified, 414 unchanged
🛸 Powered by Emerge Tools |
This is part 2/3: 1. #2345 2. 👉 #2346 3. #2347 --------------- ## Description This uses the `EnumDeserializerWithDefault` and `SealedDeserializerWithDefault` to add default cases to all enums and sealed types, except `Background` and `ButtonComponent`. Those 2 will be done in the next PR, as they have some cascading effects.
…t` (#2347) This is part 3/3: 1. #2345 2. #2346 3. 👉 #2347 --------------- ## Description Adds a new `Unknown` default case to: - `Background` - `ButtonComponent.Action` - `ButtonComponent.Destination` - `ButtonComponent.UrlMethod` And handles this new case in code: - An unknown background type will cause the paywall to fail to render, as we can't infer colors and content colors in this case. - Any unknown button action/destination/method type will cause the button to be hidden.
**This is an automatic release.** ## RevenueCat SDK ### 🐞 Bugfixes * Add missing response fields to `CustomerInfo`. Including transaction Prices (#2128) via Cesar de la Vega (@vegaro) ## RevenueCatUI SDK ### Paywallv2 #### 🐞 Bugfixes * [Paywalls v2] Fixes timeline layout when width is Fit (#2354) via JayShortway (@JayShortway) * [Paywalls V2] Improves fuzzy matching locale when the region doesn't match (#2355) via JayShortway (@JayShortway) * [Paywalls V2] Norwegian Bokmål and Norwegian Nynorsk fall back to Norwegian. (#2329) via JayShortway (@JayShortway) ### Customer Center #### 🐞 Bugfixes * Clean up on restoring functionality in customer center (#2316) via Cesar de la Vega (@vegaro) ### 🔄 Other Changes * [Paywalls v2] Adds the unsupported Background type to the error message (#2350) via JayShortway (@JayShortway) * [Paywalls v2] Uses a fixed date for template previews to avoid daily changes. (#2351) via JayShortway (@JayShortway) * [Paywalls v2] Adds a default case to `Background` and `ButtonComponent` (#2347) via JayShortway (@JayShortway) * [Paywalls v2] Improves `PaywallComponentsTemplatePreviewRecorder` stability (#2352) via JayShortway (@JayShortway) * [Paywalls v2] Adds a default case to most enums and sealed types (#2346) via JayShortway (@JayShortway) * Adds `EnumDeserializerWithDefault` and `SealedDeserializerWithDefault` (#2345) via JayShortway (@JayShortway) * [Paywalls V2] Renders template previews in a fixed resolution using Paparazzi (#2214) via JayShortway (@JayShortway) * Bump fastlane from 2.227.0 to 2.227.1 (#2344) via dependabot[bot] (@dependabot[bot]) * Migrate root gradle file to KTS (#2343) via Jaewoong Eum (@skydoves) * Migrate tester modules to KTS format (#2340) via Jaewoong Eum (@skydoves) * Introduce purchases-bom package (#2339) via Jaewoong Eum (@skydoves) * [AUTOMATIC][Paywalls V2] Updates paywall-preview-resources submodule (#2338) via RevenueCat Git Bot (@RCGitBot) * [Diagnostics] Removes Android 7 requirement (#2335) via JayShortway (@JayShortway) * [Paywalls v2] Fixes `update-paywall-preview-resources-submodule` CI job (#2337) via JayShortway (@JayShortway) * Make purchases module to transitive dependency for the ui module (#2334) via Jaewoong Eum (@skydoves) * Migrate settings.gradle to KTS and add the dependency resolutions (#2328) via Jaewoong Eum (@skydoves) Co-authored-by: revenuecat-ops <ops@revenuecat.com>
This is part 1/3:
EnumDeserializerWithDefaultandSealedDeserializerWithDefault#2345BackgroundandButtonComponent#2347Description
Adds 2 abstract serializers that will be used in the follow-up PRs to deserialize enums and sealed types with a default case.