Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 30, 2024

Maintenance ModeYou are viewing Amplify Gen 1 documentation. Amplify Gen 1 has entered maintenance mode and will reach end of life on May 1, 2027. New project should use Amplify Gen 2. For existing Gen 1 projects, a migration guide and tooling are available to help you upgrade. Switch to the latest Gen 2 docs →

DataStoreイベント

DataStoreは定期的にAmplifyのHubに状態通知を発行します。Hubをサブスクライブして、DataStoreの内部状態を知ることができます。以下の場合、イベントが発行されます:

  • デバイスがネットワーク接続を失うか、回復する場合
  • データがクラウドと同期される場合
  • クラウドと同期されていない新しい未処理の変更がある場合

以下のDataStoreイベントが定義されています:

networkStatus

DataStoreの起動時およびネットワーク状態が変わるたびに発行されます

HubPayload NetworkStatusEventには以下が含まれます:

  • active (Bool): DataStoreがクラウドに接続可能なネットワーク上にある場合はtrue、そうでない場合はfalse

subscriptionsEstablished

DataStoreがすべてのモデルへのサブスクリプション確立を終了したときに発行されます

HubPayload: N/A

syncQueriesStarted

DataStoreが初期同期クエリを実行しようとするときに発行されます

HubPayload syncQueriesStartedEventには以下が含まれます:

  • models ([String]): 各モデルのnameの配列

modelSynced

Dispatched once for each model after the model instances have been synced from the cloud

HubPayload modelSyncedEvent contains:

  • modelName (String): the name of the model that was synced
  • isFullSync (Bool): true if the model was synced with a "full" query to retrieve all models
  • isDeltaSync (Bool): true if the model was synced with a "delta" query to retrieve only changes since the last sync
  • added (Int): the number of new model instances added to the local store
  • updated (Int): the number of existing model instances updated in the local store
  • deleted (Int): the number of model instances deleted from the local store

syncQueriesReady

すべてのモデルがクラウドから同期されたときに発行されます

HubPayload: N/A

ready

DataStore全体が準備完了したときに発行されます。この時点ですべてのデータが利用可能です

HubPayload: N/A

outboxMutationEnqueued

Dispatched when a local change has been newly staged for synchronization with the Cloud

HubPayload outboxMutationEvent contains:

  • modelName (String): the name of the model that is awaiting publication to the Cloud
  • element:
    • model (Model): the model instance that will be published

outboxMutationProcessed

Dispatched when a local change has finished synchronization with the Cloud and is updated locally

HubPayload outboxMutationEvent contains:

  • modelName (String): the name of the model that has finished processing
  • element:
    • model (Model): the model instance that is processed
    • _version (Int): version of the model instance
    • _lastChangedAt (Int): last change time of model instance (unix time)
    • _deleted (Bool): true if the model instance has been deleted in Cloud

outboxMutationFailed

Dispatched when publishing a mutation fails

HubPayload outboxMutationFailed contains:

  • modelName (String): the name of the model that failed to publish
  • element:
    • model (Model): the model instance that failed to publish
    • errorType (MutationErrorType): error type that occurred
    • operation (MutationType): type of mutation that failed

outboxStatus

以下の場合に発行されます:

  • DataStoreが起動する場合
  • ローカルミューテーションがアウトボックスにキューイングされるたびに
  • ローカルミューテーションの処理が完了するたびに

HubPayload OutboxStatusEventには以下が含まれます:

  • isEmpty (Bool): クラウドへのアップロード待機中のローカル変更がないかどうかを示すブール値

使用方法

ネットワーク状態がアクティブかどうかを確認するには、以下のリスナーを設定できます:

Amplify.Hub.subscribe(
HubChannel.DATASTORE,
hubEvent -> DataStoreChannelEventName.NETWORK_STATUS.toString().equals(hubEvent.getName()),
hubEvent -> {
NetworkStatusEvent event = (NetworkStatusEvent) hubEvent.getData();
Log.i("MyAmplifyApp", "User has a network connection: " + event.getActive());
}
);
Amplify.Hub.subscribe(HubChannel.DATASTORE,
{ it.name.equals(DataStoreChannelEventName.NETWORK_STATUS.toString()) },
{
val networkStatus = it.data as NetworkStatusEvent
Log.i("MyAmplifyApp", "User has a network connection? ${networkStatus.active}")
}
)
Amplify.Hub.subscribe(DATASTORE)
{ it.name == NETWORK_STATUS.toString() }
.collect {
val event = it.data as NetworkStatusEvent
Log.i("MyAmplifyApp", "User has a network connection: ${event.active}")
}
RxAmplify.Hub.on(HubChannel.DATASTORE)
.filter(hubEvent -> DataStoreChannelEventName.NETWORK_STATUS.toString().equals(hubEvent.getName()))
.subscribe(hubEvent -> {
NetworkStatusEvent event = (NetworkStatusEvent) hubEvent.getData();
Log.i("MyAmplifyApp", "User has a network connection: " + event.getActive());
});