SubscriberAttribute: converted into struct#1648
Merged
Merged
Conversation
NachoSoto
commented
Jun 2, 2022
| import Foundation | ||
|
|
||
| class SubscriberAttribute { | ||
| struct SubscriberAttribute { |
NachoSoto
commented
Jun 2, 2022
| @DefaultDecodable.EmptyString | ||
| var value: String | ||
| @DefaultDecodable.False | ||
| var isSynced: Bool |
Contributor
Author
There was a problem hiding this comment.
This had mutable reference semantics 🤮
SubscriberAttribute to CodableSubscriberAttribute to Codable
504b93a to
76279b3
Compare
SubscriberAttribute to CodableSubscriberAttribute: converted into struct
NachoSoto
commented
Jun 16, 2022
Contributor
Author
There was a problem hiding this comment.
This is SubscriberAttribute.init?(dictionary:) now.
NachoSoto
commented
Jun 16, 2022
Contributor
Author
There was a problem hiding this comment.
This was duplicated.
76279b3 to
662850f
Compare
Initially I wanted to make `SubscriberAttribute.asDictionary` work using `Codable`. However, this isn't the right refactor because we need the actual raw types to be encoded inside `UserDefaults`. At least this refactor provides several improvements: - `SubscriberAttribute` now has value semantics - `SubscriberAttribute.isSynced` used to be mutable, with reference semantics, which was dangerous - `SubscriberAttribute: Equatable` implementation is now automatic - Cleaned up `SubscriberAttribute.asDictionary` implementation, extracting keys into an `enum` - Moved `Dictionary` -> `SubscriberAttribute` creation to the type itself - `SubscriberAttribute.init(dictionary:)` returns an `Optional` instead of using force-unwrap, avoiding potential crashes - Added more serialization / deserialization tests - Removed `SubscriberAttributesMarshaller` and moved method into `SubscriberAttribute` extension - Moved `SubscriberAttributeDict` into `SubscriberAttribute.Dictionary`
662850f to
a0a0731
Compare
NachoSoto
commented
Jun 16, 2022
| expect(self.deviceCache.isOfferingsCacheStale(isAppBackgrounded: true)) == false | ||
| } | ||
|
|
||
| func testInitWithDictionarySetsRightValues() { |
Contributor
Author
There was a problem hiding this comment.
This is tested in SubscriberAttributeTests now since the implementation is there.
NachoSoto
commented
Jun 16, 2022
|
|
||
| let receivedDictionary = subscriberAttribute.asBackendDictionary() | ||
| expect(receivedDictionary.keys.count) == 2 | ||
| func testEncodeAndDecode() throws { |
Contributor
Author
There was a problem hiding this comment.
This important new test ensures that encoding + decoding results in the same data.
NachoSoto
commented
Jun 16, 2022
|
|
||
| enum SubscriberAttributesMarshaller { | ||
|
|
||
| // fixme: make `SubscriberAttributeDict` `Encodable` instead |
Contributor
Author
There was a problem hiding this comment.
This was the goal of this PR, but as I explained in the description it didn't make sense. At least the existing implementation is cleaner now.
taquitos
approved these changes
Jun 16, 2022
taquitos
left a comment
Contributor
There was a problem hiding this comment.
Great change, only one update, then 🚢🐐
Merged
NachoSoto
added a commit
that referenced
this pull request
Jul 4, 2022
### Changes: * Replaced `CustomerInfo.nonSubscriptionTransactions` with a new non-`StoreTransaction` type (#1733) via NachoSoto (@NachoSoto) * `Purchases.configure`: added overload taking a `Configuration.Builder` (#1720) via NachoSoto (@NachoSoto) * Extract Attribution logic out of Purchases (#1693) via Joshua Liebowitz (@taquitos) * Remove create alias (#1695) via Joshua Liebowitz (@taquitos) All attribution APIs can now be accessed from `Purchases.shared.attribution`. ### Improvements: * Improved purchasing logs, added promotional offer information (#1725) via NachoSoto (@NachoSoto) * `PurchasesOrchestrator`: don't log attribute errors if there are none (#1742) via NachoSoto (@NachoSoto) * `FatalErrorUtil`: don't override `fatalError` on release builds (#1736) via NachoSoto (@NachoSoto) * `SKPaymentTransaction`: added more context to warnings about missing properties (#1731) via NachoSoto (@NachoSoto) * New SwiftUI Purchase Tester example (#1722) via Josh Holtz (@joshdholtz) * update docs for `showManageSubscriptions` (#1729) via aboedo (@aboedo) * `PurchasesOrchestrator`: unify finish transactions between SK1 and SK2 (#1704) via NachoSoto (@NachoSoto) * `SubscriberAttribute`: converted into `struct` (#1648) via NachoSoto (@NachoSoto) * `CacheFetchPolicy.notStaleCachedOrFetched`: added warning to docstring (#1708) via NachoSoto (@NachoSoto) * Clear cached offerings and products after Storefront changes (2/4) (#1583) via Juanpe Catalán (@Juanpe) * `ROT13`: optimized initialization and removed magic numbers (#1702) via NachoSoto (@NachoSoto) ### Fixes: * `logIn`/`logOut`: sync attributes before aliasing (#1716) via NachoSoto (@NachoSoto) * `Purchases.customerInfo(fetchPolicy:)`: actually use `fetchPolicy` parameter (#1721) via NachoSoto (@NachoSoto) * `PurchasesOrchestrator`: fix behavior dealing with `nil` `SKPaymentTransaction.productIdentifier` during purchase (#1680) via NachoSoto (@NachoSoto) * `PurchasesOrchestrator.handlePurchasedTransaction`: always refresh receipt data (#1703) via NachoSoto (@NachoSoto)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
Initially I wanted to make
SubscriberAttribute.asDictionarywork usingCodable. However, this isn't the right refactor because we need the actual raw types to be encoded insideUserDefaults.At least this refactor provides several improvements:
Changes:
SubscriberAttributenow has value semanticsSubscriberAttribute.isSyncedused to be mutable, with reference semantics, which was dangerousSubscriberAttribute: Equatableimplementation is now automaticSubscriberAttribute.asDictionaryimplementation, extracting keys into anenumDictionary->SubscriberAttributecreation to the type itselfSubscriberAttribute.init(dictionary:)returns anOptionalinstead of using force-unwrap, avoiding potential crashesSubscriberAttributesMarshallerand moved method intoSubscriberAttributeextensionSubscriberAttributeDictintoSubscriberAttribute.Dictionary