-
Notifications
You must be signed in to change notification settings - Fork 203
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
feat(DataStore): DisableSubscriptions flag for watchOS #3368
Changes from all commits
b622589
98d4759
63beeff
5c6a6a6
974940a
7ab1b22
14d2cae
34970a2
e0d1f41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,42 @@ extension DataStoreConfiguration { | |
public static let defaultSyncMaxRecords: UInt = 10_000 | ||
public static let defaultSyncPageSize: UInt = 1_000 | ||
|
||
#if os(watchOS) | ||
/// Creates a custom configuration. The only required property is `conflictHandler`. | ||
/// | ||
/// - Parameters: | ||
/// - errorHandler: a callback function called on unhandled errors | ||
/// - conflictHandler: a callback called when a conflict could not be resolved by the service | ||
/// - syncInterval: how often the sync engine will run (in seconds) | ||
/// - syncMaxRecords: the number of records to sync per execution | ||
/// - syncPageSize: the page size of each sync execution | ||
/// - authModeStrategy: authorization strategy (.default | multiauth) | ||
sebaland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// - disableSubscriptions: called before establishing subscriptions. Return true to disable subscriptions. | ||
/// - Returns: an instance of `DataStoreConfiguration` with the passed parameters. | ||
public static func custom( | ||
errorHandler: @escaping DataStoreErrorHandler = { error in | ||
Amplify.Logging.error(error: error) | ||
}, | ||
conflictHandler: @escaping DataStoreConflictHandler = { _, resolve in | ||
resolve(.applyRemote) | ||
}, | ||
syncInterval: TimeInterval = DataStoreConfiguration.defaultSyncInterval, | ||
syncMaxRecords: UInt = DataStoreConfiguration.defaultSyncMaxRecords, | ||
syncPageSize: UInt = DataStoreConfiguration.defaultSyncPageSize, | ||
syncExpressions: [DataStoreSyncExpression] = [], | ||
authModeStrategy: AuthModeStrategyType = .default, | ||
disableSubscriptions: @escaping () -> Bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This name is a bit confusing, as it's actually more of a "delegate" callback than a setter. How about |
||
) -> DataStoreConfiguration { | ||
return DataStoreConfiguration(errorHandler: errorHandler, | ||
conflictHandler: conflictHandler, | ||
syncInterval: syncInterval, | ||
syncMaxRecords: syncMaxRecords, | ||
syncPageSize: syncPageSize, | ||
syncExpressions: syncExpressions, | ||
authModeStrategy: authModeStrategy, | ||
disableSubscriptions: disableSubscriptions) | ||
} | ||
#else | ||
/// Creates a custom configuration. The only required property is `conflictHandler`. | ||
/// | ||
/// - Parameters: | ||
|
@@ -46,10 +82,32 @@ extension DataStoreConfiguration { | |
syncExpressions: syncExpressions, | ||
authModeStrategy: authModeStrategy) | ||
} | ||
|
||
#endif | ||
|
||
#if os(watchOS) | ||
/// Default configuration with subscriptions disabled for watchOS. DataStore uses subscriptions via websockets, | ||
/// which work on the watchOS simulator but not on the device. Running DataStore on watchOS with subscriptions | ||
/// enabled is only possible during special circumstances such as actively streaming audio. | ||
/// See https://github.com/aws-amplify/amplify-swift/pull/3368 for more details. | ||
public static var subscriptionsDisabled: DataStoreConfiguration { | ||
.custom(disableSubscriptions: { false }) | ||
} | ||
sebaland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#else | ||
/// The default configuration. | ||
public static var `default`: DataStoreConfiguration { | ||
.custom() | ||
} | ||
|
||
#endif | ||
|
||
#if os(watchOS) | ||
/// Internal method for testing | ||
static func testDefault(disableSubscriptions: @escaping () -> Bool = { false }) -> DataStoreConfiguration { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of the name, but I also can't think of anything other than |
||
.custom(disableSubscriptions: disableSubscriptions) | ||
} | ||
#else | ||
/// Internal method for testing | ||
static func testDefault() -> DataStoreConfiguration { | ||
.custom() | ||
} | ||
#endif | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will revert