-
Notifications
You must be signed in to change notification settings - Fork 202
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
Conversation
2c90416
to
ad032ec
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## lawmicha.int64 #3368 +/- ##
=================================================
Coverage ? 67.99%
=================================================
Files ? 1078
Lines ? 36002
Branches ? 0
=================================================
Hits ? 24480
Misses ? 11522
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
ad032ec
to
145387b
Compare
145387b
to
e427d72
Compare
...ugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration+Helper.swift
Show resolved
Hide resolved
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 comment
The 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 areSubscriptionsDisabled
or something like that?
Alternatively we can make this an actual non-optional delegate, but it's probably an overkill at this point.
|
||
#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 comment
The 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 internalDefault
, which I equally dislike 😅
AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin.swift
Outdated
Show resolved
Hide resolved
...ugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration+Helper.swift
Show resolved
Hide resolved
AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin.swift
Show resolved
Hide resolved
…efault' for shared testing. force plugin initializer to take in configuration for watchOS
371f6bb
to
e0d1f41
Compare
Issue #
#3220
Table of Contents
Description
DataStore’s sync engine currently does not start successfully on watchOS. The reason for this is due to the lack of low-level networking capabilities on watchOS, which DataStore uses when establishing subscriptions for real-time data. When DataStore’s sync engine attempts to establish the websocket connection, it will hang on connecting, never completing the sync engine activation steps.
Low-level networking on watchOS is limited but there are special circumstances in which an app does allow low-level networking, such as websockets, to work. They are listed here:
This PR introduces a required client configuration option to disable subscriptions when building on watchOS. When building an watchOS app, set this value to what is required for your app to work properly. In most cases, if you are not operating in the special circumstance, then set the implementation of
disableSubscriptions
to return trueLimited Functionality
With this value set to
true
, during the runtime of the app, data saved from other devices will not appear on the current device until DataStore has been restarted.DataStore will start when any of the DataStore operations are called, or explicitly through
DataStore.start()
. When it starts, it will sync the latest data from the remote store.Force restart DataStore
You may find it useful to restart DataStore by calling
DataStore.stop()
followed byDataStore.start()
in parts of you application such as navigating to a view of the app that uses data from DataStore or based on some end-user actions.Conflict Handler
If two devices are operating on the same model data, and DataStore is running without subscriptions, there will likely be conflicts. To handle conflicting updates, based on your use cases, you can implement
conflictHandler
to make decisions such as when there's a conflict, to retry the local model, remote model, or a merged model to be re-synced. See conflict resolution for more detailsSpecial Circumstances
If you are building a watchOS app in which uses low-level networking during the special circumstance, you can re-enable subscriptions to get real-time updates during the special circumstances:
General Checklist
Given When Then
inline code documentation and are named accordinglytestThing_condition_expectation()
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.