Skip to content

Commit

Permalink
networkStatus not implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ruiguoamz committed Aug 25, 2020
2 parents f240138 + 55d36b9 commit 5fcc641
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
Amplify.Hub.removeListener(token)
}
}

let payloadOfOutboxStatus = HubPayload(eventName: HubPayload.EventName.DataStore.outboxStatusChanged)
Amplify.Hub.dispatch(to: .dataStore, payload: payloadOfOutboxStatus)

let payload = HubPayload(eventName: HubPayload.EventName.DataStore.ready)
Amplify.Hub.dispatch(to: .dataStore, payload: payload)
}

func reinitStorageEngineIfNeeded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,42 @@ final class InitialSyncOperation: AsynchronousOperation {
log.info("Beginning sync for \(modelType.modelName)")
let lastSyncTime = getLastSyncTime()
query(lastSyncTime: lastSyncTime)

var modelSyncedPayload = ModelSyncedPayload()
modelSyncedPayload.modelName = modelType.modelName
modelSyncedPayload.isFullSync = lastSyncTime == 0 ? true : false
modelSyncedPayload.isDeltaSync = !modelSyncedPayload.isFullSync

guard let reconciliationQueue = reconciliationQueue else {
return
}

_ = reconciliationQueue.publisher.sink(
receiveCompletion: { result in
print(result)
}, receiveValue: { result in
print(result)
switch result {
case .initialized, .started, .paused:
print(result)
case .mutationEvent(let mutationEvent):
modelSyncedPayload.modelName = mutationEvent.modelName
switch mutationEvent.mutationType {
case "create":
modelSyncedPayload.createCount += 1
case "update":
modelSyncedPayload.updateCount += 1
case "delete":
modelSyncedPayload.deleteCount += 1
default:
print(result)
}
}
})

let payload = HubPayload(eventName: HubPayload.EventName.DataStore.modelSynced,
data: modelSyncedPayload)
Amplify.Hub.dispatch(to: .dataStore, payload: payload)
}

private func getLastSyncTime() -> Int? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ class RemoteSyncEngine: RemoteSyncEngineBehavior {
Amplify.Hub.dispatch(to: .dataStore,
payload: HubPayload(eventName: HubPayload.EventName.DataStore.syncStarted))

Amplify.Hub.dispatch(to: .dataStore,
payload: HubPayload(eventName: HubPayload.EventName.DataStore.ready))

remoteSyncTopicPublisher.send(.syncStarted)
stateMachine.notify(action: .notifiedSyncStarted)
}
Expand Down

0 comments on commit 5fcc641

Please sign in to comment.