From 22088ab7755afb17a49175e5d3ff668fbb3dcdf6 Mon Sep 17 00:00:00 2001
From: "Vincent (Wen Yu) Ge"
+ Appwrite Offline allows your client apps to continue functioning without an internet connection. Your users' mobile devices frequently encounter situations where internet access becomes unstable or temporarily unavailable, like when going through tunnels, getting on airplanes and subways, or going in and out of WIFI range. Offline helps your app gracefully handle these real life situations and keep your users engaged.
+
+ Appwrite Offline allows you to continue making requests to Appwrite APIs while offline through a cache. While offline, read requests will be fetched from the local cache data, and write requests will be queued and executed once the device is online again.
+
+ You should consider enabling Offline if you expect the user device running your application to experience short periods without a network connection, like going on an airplane to going through a tunnel. Offline can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect you app to be offline for days or weeks at a time, you may also need to find alternative solutions.
+
+ Offline support adds a cache layer that takes up additional resources and adds overhead to your requests. This may not be desirable for some applications, especially if it's not expected to be used without a stable internet connection.
+
+ When Offline is enabled, it will change how promises are resolved in the Appwrite SDKs. Requests made Offline can become blocking, which means you will need to change how you handle promises in your application. This means you may need to rewrite some of your code when adding Offline to existing applications.
+
- Appwrite Offline allows your client apps to continue functioning without an internet connection. Your users' mobile devices frequently encounter situations where internet access becomes unstable or temporarily unavailable, like when going through tunnels, getting on airplanes and subways, or going in and out of WIFI range. Offline helps your app gracefully handle these real life situations and keep your users engaged.
+ The Appwrite SDKs' Offline Support allows your client apps to continue functioning without an internet connection. Your users' mobile devices frequently encounter situations where internet access becomes unstable or temporarily unavailable, like when going through tunnels, getting on airplanes and subways, or going in and out of Wi-Fi range. Offline Support helps your app gracefully handle these real-life situations and keeps your users engaged.
When Should I Enable Offline?
+
Tradeoffs of Enabling Offline
+
When Should I Enable Offline?
From a5cf410b799d18a436a21fc2d2a1fe0c88ebb28a Mon Sep 17 00:00:00 2001
From: "Vincent (Wen Yu) Ge"
Appwrite Offline allows you to continue making requests to Appwrite APIs while offline through a cache. While offline, read requests will be fetched from the local cache data, and write requests will be queued and executed once the device is online again.
From 2cc25998695b7c6866fc02eb3cf2db5ae00c71e9 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge"- You should consider enabling Offline if you expect the user device running your application to experience short periods without a network connection, like going on an airplane to going through a tunnel. Offline can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect you app to be offline for days or weeks at a time, you may also need to find alternative solutions. + You should consider enabling Offline Support if you expect the user device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel. Offline can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks at a time, you may also need to find alternative solutions.
- Appwrite Offline allows you to continue making requests to Appwrite APIs while offline through a cache. While offline, read requests will be fetched from the local cache data, and write requests will be queued and executed once the device is online again. + With Offline Support enabled, your app can continue sending requests to Appwrite APIs while offline through a cache. While offline, read requests will be fetched from the local cache data, and write requests will be queued and executed once the device is online again.
You should consider enabling Offline Support if you expect the user device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel. Offline can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks at a time, you may also need to find alternative solutions.
From c84c16071a56f32ec3c27e6ebd56884d9f5077c9 Mon Sep 17 00:00:00 2001
From: "Vincent (Wen Yu) Ge"
Offline support adds a cache layer that takes up additional resources and adds overhead to your requests. This may not be desirable for some applications, especially if it's not expected to be used without a stable internet connection.
From 4894a138468c51898f1b14c5f6daaa7bce9850ce Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge"- When Offline is enabled, it will change how promises are resolved in the Appwrite SDKs. Requests made Offline can become blocking, which means you will need to change how you handle promises in your application. This means you may need to rewrite some of your code when adding Offline to existing applications. + When Offline Support is enabled, it will change how API calls are made in the Appwrite SDKs. Write requests made while offline will not return until online again, which means you will need to change how you call these methods in your application. This means you may need to rewrite some of your code when adding Offline Support to existing applications.
\ No newline at end of file From 69e5c823d0c2c07622c6476d1dba8e21f02dd2c7 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge"With Offline Support enabled, your app can continue sending requests to Appwrite APIs while offline through a cache. While offline, read requests will be fetched from the local cache data, and write requests will be queued and executed once the device is online again.
@@ -10,10 +10,11 @@ You should consider enabling Offline Support if you expect the user device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel. Offline can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks at a time, you may also need to find alternative solutions. -- Offline support adds a cache layer that takes up additional resources and adds overhead to your requests. This may not be desirable for some applications, especially if it's not expected to be used without a stable internet connection. + Offline Support adds a cache layer that takes up additional resources and adds overhead to your requests. This may not be desirable for some applications, especially if it's not expected to be used without a stable internet connection.
+- When Offline Support is enabled, it will change how API calls are made in the Appwrite SDKs. Write requests made while offline will not return until online again, which means you will need to change how you call these methods in your application. This means you may need to rewrite some of your code when adding Offline Support to existing applications. + Promises may not resolve immediately when Offline Support is enabled. Existing projects will require some code to be rewritten when adopting Offline Support. Learn more about promise resolution.
\ No newline at end of file From ae66a2ba4af2bd8d006eaf4e4ffbb51b2b022f91 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge"- You should consider enabling Offline Support if you expect the user device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel. Offline can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks at a time, you may also need to find alternative solutions. + You should consider enabling Offline Support if you expect the user device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel. Offline Support can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks at a time, you may also need to find alternative solutions.
- Promises may not resolve immediately when Offline Support is enabled. Existing projects will require some code to be rewritten when adopting Offline Support. Learn more about promise resolution. + Asynchronous operations may not resolve immediately when Offline Support is enabled. Existing projects will require some code to be rewritten when adopting Offline Support. Learn more about how to handle asynchronous operation.
\ No newline at end of file From 8c0b39e89d9514590975fa3eef637a839592b433 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge"- With Offline Support enabled, your app can continue sending requests to Appwrite APIs while offline through a cache. While offline, read requests will be fetched from the local cache data, and write requests will be queued and executed once the device is online again. + With Offline Support enabled, your app can continue sending requests to Appwrite APIs while offline through a cache. While offline, read requests will be fetched from the local cached data, and write requests will be queued and executed once the device is online again.
You should consider enabling Offline Support if you expect the user device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel. Offline Support can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks at a time, you may also need to find alternative solutions.
From 5828b058e7a9fe2814b87101579ec8b0635ef054 Mon Sep 17 00:00:00 2001
From: "Vincent (Wen Yu) Ge"
- You should consider enabling Offline Support if you expect the user device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel. Offline Support can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks at a time, you may also need to find alternative solutions. + You should consider enabling Offline Support if you expect the device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel. Offline Support can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks at a time, you may also need to find alternative solutions.
- With Offline Support enabled, your app can continue sending requests to Appwrite APIs while offline through a cache. While offline, read requests will be fetched from the local cached data, and write requests will be queued and executed once the device is online again. + You should consider enabling Offline Support if you expect the device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel. Offline Support can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks at a time, you may also need to find alternative solutions.
+ +- You should consider enabling Offline Support if you expect the device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel. Offline Support can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks at a time, you may also need to find alternative solutions. +
-
- Offline Support adds a cache layer that takes up additional resources and adds overhead to your requests. This may not be desirable for some applications, especially if it's not expected to be used without a stable internet connection.
+ Offline Support can be enabled by setting setOffilnePersistency
to true on your SDK's client.
- Asynchronous operations may not resolve immediately when Offline Support is enabled. Existing projects will require some code to be rewritten when adopting Offline Support. Learn more about how to handle asynchronous operation. -
\ No newline at end of file + Offline Support will cache all read request in a Least Recently Used (LRU) cache, so the information can remain available even with no internet connection. The LRU cache defaults to a size of 16KB and can be configured using thesetOfflineCacheSize
method.
+
+
+[TODO: Code Example]
+
++ When Offline Support is enabled, asynchronous operations only resolve after the request is accepted by the server. Requests made with the Client SDK may block code execution until network connection is available again. +
+[TODO: Show UML diagram] + ++ For example, the code example below will block code execution when the device is offline. +
+ +[TODO: Show Example, in comments clearly mark that it's ] + ++ To avoid blocking code execution, asynchronous operations should be handled [TODO: fill description] +
+ +[TODO: Show correct version of example. ] + ++ With Offline Support enabled, your app can continue sending requests to Appwrite APIs while offline through a cache when offline. Read requests will be fetched from the local cached data, and write requests will be queued and executed once the device is online again. This can lead to write conflicts when the device is online again. +
++ [TODO: Describe resolution behavior + tips if available.] +
+ ++ Additional considerations need to be considered when updating data based on the current value, such as incrementing a counter or appending values to then end of a paragraph. The default conflict resolution behavior may result in incorrect updates and writes. Consider disabling these operations while offline or use Appwrite Functions to implement logic to resolve conflicts. +
+ + + From e6ed7e089d3e2ca0ebfe0f441c70b8a0a0b008ae Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge"- -
Offline Support can be enabled by setting setOffilnePersistency
to true on your SDK's client.
Enabling Offline Support introduces breaking changes to the behavior of Client SDKs. Asynchronous operations may not resolve until the device is online again. Existing projects will have to be updated.
+ +
Offline Support will cache all read request in a Least Recently Used (LRU) cache, so the information can remain available even with no internet connection. The LRU cache defaults to a size of 16KB and can be configured using the setOfflineCacheSize
method.
@@ -23,7 +26,7 @@
[TODO: Code Example]
-
When Offline Support is enabled, asynchronous operations only resolve after the request is accepted by the server. Requests made with the Client SDK may block code execution until network connection is available again.
From 1f2c4773f4cd8edc7da48a78efb9e684d15ac722 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge"- When Offline Support is enabled, asynchronous operations only resolve after the request is accepted by the server. Requests made with the Client SDK may block code execution until network connection is available again. + When Offline Support is enabled, asynchronous write operations only resolve after the server accepts the request. Requests made with the Client SDK may block code execution until network connection is available again.
[TODO: Show UML diagram] From 3f2c85aedada9fcc4bc6f0316f14c2cc9553744f Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge"
- Offline Support will cache all read request in a Least Recently Used (LRU) cache, so the information can remain available even with no internet connection. The LRU cache defaults to a size of 16KB and can be configured using the setOfflineCacheSize
method.
+ Offline Support will cache all read request in a Least Recently Used (LRU) cache, so the information can remain available even with no internet connection. The LRU cache defaults to a size of 16MB and can be configured using the setOfflineCacheSize
method.
Learn more about asynchronous operations
-[TODO: Code Example] +client.setOfflinePersistency(status: true);
+
Offline Support will cache all read request in a Least Recently Used (LRU) cache, so the information can remain available even with no internet connection. The LRU cache defaults to a size of 16MB and can be configured using the setOfflineCacheSize
method.
client.setOfflineCacheSize(40000);
+@@ -35,14 +39,28 @@
For example, the code example below will block code execution when the device is offline.
- -[TODO: Show Example, in comments clearly mark that it's ] +// This await will not resolve until your device is online
+final document = await databases.createDocument(
+ databaseId: '[DATABASE_ID]',
+ collectionId: '[COLLECTION_ID]',
+ documentId: ID.unique(),
+ data: {},
+);
+- To avoid blocking code execution, asynchronous operations should be handled [TODO: fill description] + To avoid blocking code execution, update local states and UI optimisitically instead of waiting for awaiting asynchronous operations.
-[TODO: Show correct version of example. ] +final document = databases.createDocument(
+ databaseId: '[DATABASE_ID]',
+ collectionId: '[COLLECTION_ID]',
+ documentId: ID.unique(),
+ data: {},
+);
+
From 8e66831a70a00476566ed89ea36f7ff2183e99b9 Mon Sep 17 00:00:00 2001
From: "Vincent (Wen Yu) Ge"
- [TODO: Describe resolution behavior + tips if available.] + Document updates made while your device is offline will be queued locally with a timestamp. When your device comes online, Appwrite will compare the timestamps of local updates with the timestamp of the remote document, accepting the latest version. Appwrite will reject a document update if the remote document been updated later than the locally queued update.
From 0c0680e77f87977a0ef381dac2c395fc3bc47102 Mon Sep 17 00:00:00 2001
From: "Vincent (Wen Yu) Ge"
// This await will not resolve until your device is online
-final document = await databases.createDocument(
- databaseId: '[DATABASE_ID]',
- collectionId: '[COLLECTION_ID]',
- documentId: ID.unique(),
- data: {},
-);
+ void blockingSubmitTodo() async {
+ if (inputController.text.isEmpty || isLoading) return;
+ final messenger = ScaffoldMessenger.of(context);
+ final newTodo = Todo(
+ content: inputController.text,
+ id: ID.unique(),
+ );
+
+ try {
+ await _databases.createDocument(
+ databaseId: '[DATABASE_ID]',
+ collectionId: '[COLLECTION_ID]',
+ documentId: newTodo.id,
+ data: {
+ "content": newTodo.content,
+ "isComplete": newTodo.isComplete,
+ },
+ );
+ inputController.text = '';
+ todos.add(newTodo);
+ } catch (e) {
+ messenger.showSnackBar(createErrorSnackBar(e.toString()));
+ }
+
+ setState(() {
+ isLoading = false;
+ });
+ }
@@ -54,12 +75,33 @@ final document = await databases.createDocument(
final document = databases.createDocument(
- databaseId: '[DATABASE_ID]',
- collectionId: '[COLLECTION_ID]',
- documentId: ID.unique(),
- data: {},
-);
+ void nonBlockingSubmitTodo() async {
+ if (inputController.text.isEmpty || isLoading) return;
+ final messenger = ScaffoldMessenger.of(context);
+ final newTodo = Todo(
+ content: inputController.text,
+ id: ID.unique(),
+ );
+
+ _databases.createDocument(
+ databaseId: '[DATABASE_ID]',
+ collectionId: '[COLLECTION_ID]',
+ documentId: newTodo.id,
+ data: {
+ "content": newTodo.content,
+ "isComplete": newTodo.isComplete,
+ },
+ ).catchError((e) {
+ messenger.showSnackBar(createErrorSnackBar(e.toString()));
+ todos.remove(newTodo);
+ });
+
+ setState(() {
+ inputController.text = '';
+ todos.add(newTodo);
+ isLoading = false;
+ });
+ }
- The Appwrite SDKs' Offline Support allows your client apps to continue functioning without an internet connection. Your users' mobile devices frequently encounter situations where internet access becomes unstable or temporarily unavailable, like when going through tunnels, getting on airplanes and subways, or going in and out of Wi-Fi range. Offline Support helps your app gracefully handle these real-life situations and keeps your users engaged. + Offline Support allows your client apps to continue functioning without an internet connection. Mobile devices frequently encounter situations where internet access becomes unstable or temporarily unavailable, like going through tunnels, getting on airplanes and subways, or going in and out of Wi-Fi range. Offline Support keeps your users engaged when transitioning through these real-life situations.
-- You should consider enabling Offline Support if you expect the device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel. Offline Support can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks at a time, you may also need to find alternative solutions. + You should consider enabling Offline Support if you expect the device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel.
- -
- Offline Support can be enabled by setting setOffilnePersistency
to true on your SDK's client.
+ Offline Support can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks, you may need to find alternative solutions.
Enabling Offline Support introduces breaking changes to the behavior of Client SDKs. Asynchronous operations may not resolve until the device is online again. Existing projects will have to be updated.
-Learn more about asynchronous operations
+Enabling Offline Support introduces breaking changes to the asynchronous operation behavior of Client SDKs. Existing projects must be updated.
+
+ You can enable Offline Support by setting setOffilnePersistency
to true on your SDK's client.
+
client.setOfflinePersistency(status: true);
- Offline Support will cache all read request in a Least Recently Used (LRU) cache, so the information can remain available even with no internet connection. The LRU cache defaults to a size of 16MB and can be configured using the setOfflineCacheSize
method.
+ Offline Support will cache all read requests in a Least Recently Used (LRU) cache, so the information can remain available without internet connection. The LRU cache defaults to 16MB and can be configured using the setOfflineCacheSize
method.
client.setOfflineCacheSize(40000);
- When Offline Support is enabled, asynchronous write operations only resolve after the server accepts the request. Requests made with the Client SDK may block code execution until network connection is available again. + When Offline Support is enabled, write operations only resolve after the server accepts the request. Requests made with the Client SDK may block code execution until network connection is available again.
+ ++ You should optimistically update your app's local state after a write operation. Once you're online again, the write will be synced with your Appwrite project, which will be fetched when you app restarts in the future. +
+ +setParam('srcLight', '/images-ee/docs/offline-writes-uml-light.png') + ->setParam('srcDark', '/images-ee/docs/offline-writes-uml-light.png') + ->setParam('alt', 'Function settings page.') + ->setParam('description', 'Function settings page.') + ->render(); +?> [TODO: Show UML diagram] +For example, the code example below will block code execution when the device is offline.
void blockingSubmitTodo() async {
- if (inputController.text.isEmpty || isLoading) return;
- final messenger = ScaffoldMessenger.of(context);
- final newTodo = Todo(
- content: inputController.text,
- id: ID.unique(),
+ void blockingSubmitTodo() async {
+ if (inputController.text.isEmpty || isLoading) return;
+ final messenger = ScaffoldMessenger.of(context);
+ final newTodo = Todo(
+ content: inputController.text,
+ id: ID.unique(),
+ );
+
+ try {
+ // THIS BLOCKS EXECUTION WHEN OFFLINE
+ await _databases.createDocument(
+ databaseId: '[DATABASE_ID]',
+ collectionId: '[COLLECTION_ID]',
+ documentId: newTodo.id,
+ data: {
+ "content": newTodo.content,
+ "isComplete": newTodo.isComplete,
+ },
);
-
- try {
- await _databases.createDocument(
- databaseId: '[DATABASE_ID]',
- collectionId: '[COLLECTION_ID]',
- documentId: newTodo.id,
- data: {
- "content": newTodo.content,
- "isComplete": newTodo.isComplete,
- },
- );
- inputController.text = '';
- todos.add(newTodo);
- } catch (e) {
- messenger.showSnackBar(createErrorSnackBar(e.toString()));
- }
-
- setState(() {
- isLoading = false;
- });
- }
+ inputController.text = '';
+ todos.add(newTodo);
+ } catch (e) {
+ // ... handle errors
+ }
+
+ setState(() {
+ isLoading = false;
+ });
+}
@@ -83,6 +111,7 @@ id: ID.unique(), ); + // This won't block execution, but will still allow error handling. _databases.createDocument( databaseId: '[DATABASE_ID]', collectionId: '[COLLECTION_ID]', @@ -92,8 +121,7 @@ "isComplete": newTodo.isComplete, }, ).catchError((e) { - messenger.showSnackBar(createErrorSnackBar(e.toString())); - todos.remove(newTodo); + // ... handle errors }); setState(() { @@ -104,17 +132,18 @@ } -
- With Offline Support enabled, your app can continue sending requests to Appwrite APIs while offline through a cache when offline. Read requests will be fetched from the local cached data, and write requests will be queued and executed once the device is online again. This can lead to write conflicts when the device is online again. -
+- Document updates made while your device is offline will be queued locally with a timestamp. When your device comes online, Appwrite will compare the timestamps of local updates with the timestamp of the remote document, accepting the latest version. Appwrite will reject a document update if the remote document been updated later than the locally queued update. + With Offline Support enabled, your app can continue sending requests to Appwrite APIs while offline through a cache when offline. Read requests will be fetched from the locally cached data. Write requests will be queued and executed once the device is online again. This can lead to conflicts if another device makes a different change.
+- Additional considerations need to be considered when updating data based on the current value, such as incrementing a counter or appending values to then end of a paragraph. The default conflict resolution behavior may result in incorrect updates and writes. Consider disabling these operations while offline or use Appwrite Functions to implement logic to resolve conflicts. + Document updates made while your device is offline will be queued locally with a timestamp. When your device comes online, Appwrite will use the timestamps to accept the latest version of the document. Appwrite will reject a document update if the remote document has been updated later than the local document.
- - ++ Additional considerations need to be considered when updating data based on the current value, such as incrementing a counter or appending values to the end of a paragraph. The default conflict resolution behavior may result in incorrect updates and writes. Consider disabling these operations while offline or using Appwrite Functions to implement logic to resolve conflicts. +
\ No newline at end of file From 2fc9646dd61a2e49fd7ef1ba40ac19e4b747fdcd Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge"void blockingSubmitTodo() async {
- if (inputController.text.isEmpty || isLoading) return;
- final messenger = ScaffoldMessenger.of(context);
- final newTodo = Todo(
- content: inputController.text,
- id: ID.unique(),
- );
+ void blockingSubmitTodo(Map todo) async {
try {
// THIS BLOCKS EXECUTION WHEN OFFLINE
@@ -81,12 +75,8 @@ $image = new View(__DIR__.'/../general/image.phtml');
databaseId: '[DATABASE_ID]',
collectionId: '[COLLECTION_ID]',
documentId: newTodo.id,
- data: {
- "content": newTodo.content,
- "isComplete": newTodo.isComplete,
- },
+ data: todo,
);
- inputController.text = '';
todos.add(newTodo);
} catch (e) {
// ... handle errors
@@ -103,29 +93,19 @@ $image = new View(__DIR__.'/../general/image.phtml');
- void nonBlockingSubmitTodo() async {
- if (inputController.text.isEmpty || isLoading) return;
- final messenger = ScaffoldMessenger.of(context);
- final newTodo = Todo(
- content: inputController.text,
- id: ID.unique(),
- );
+ void nonBlockingSubmitTodo(Map todo) async {
// This won't block execution, but will still allow error handling.
_databases.createDocument(
databaseId: '[DATABASE_ID]',
collectionId: '[COLLECTION_ID]',
documentId: newTodo.id,
- data: {
- "content": newTodo.content,
- "isComplete": newTodo.isComplete,
- },
+ data: todo,
).catchError((e) {
// ... handle errors
});
setState(() {
- inputController.text = '';
todos.add(newTodo);
isLoading = false;
});
From 93ed5e4d364b1c04d6fc5461f8a1ef58ef88ad03 Mon Sep 17 00:00:00 2001
From: "Vincent (Wen Yu) Ge"
Date: Mon, 20 Mar 2023 18:15:20 +0000
Subject: [PATCH 23/30] Fix code examples
---
app/views/docs/offline.phtml | 46 +++++++++++++++++++++++-------------
1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/app/views/docs/offline.phtml b/app/views/docs/offline.phtml
index fca610bef..e29158ae2 100644
--- a/app/views/docs/offline.phtml
+++ b/app/views/docs/offline.phtml
@@ -42,26 +42,40 @@ use Appwrite\Utopia\View;
client.setOfflineCacheSize(40000);
+Offline Support Cache
+
+When Offline Support is enabled, Appwrite allows you to query and write data by adding a cache layer.
+
+
+Reading Data Offline
+
+ Queries will fetch data from Appwrite and update the cache while the device is online. If the device is not connected to the internet, the query fetches data from the local cache.
+
+
+
+
+Writing Data Offline
+
+ Writes will update the local cache first. If the device is online, the changes will be sent to Appwrite immediately. If the device is not connected to the internet, the operation will be queued and synced to Appwrite when internet is available again.
+
+
+
+
Asynchronous Operation
When Offline Support is enabled, write operations only resolve after the server accepts the request. Requests made with the Client SDK may block code execution until network connection is available again.
-
+
You should optimistically update your app's local state after a write operation. Once you're online again, the write will be synced with your Appwrite project, which will be fetched when you app restarts in the future.
-setParam('srcLight', '/images-ee/docs/offline-writes-uml-light.png')
- ->setParam('srcDark', '/images-ee/docs/offline-writes-uml-light.png')
- ->setParam('alt', 'Function settings page.')
- ->setParam('description', 'Function settings page.')
- ->render();
-?>
-[TODO: Show UML diagram]
-
Example
For example, the code example below will block code execution when the device is offline.
@@ -74,10 +88,10 @@ $image = new View(__DIR__.'/../general/image.phtml');
await _databases.createDocument(
databaseId: '[DATABASE_ID]',
collectionId: '[COLLECTION_ID]',
- documentId: newTodo.id,
+ documentId: todo.id,
data: todo,
);
- todos.add(newTodo);
+ todos.add(todo);
} catch (e) {
// ... handle errors
}
@@ -99,14 +113,14 @@ $image = new View(__DIR__.'/../general/image.phtml');
_databases.createDocument(
databaseId: '[DATABASE_ID]',
collectionId: '[COLLECTION_ID]',
- documentId: newTodo.id,
+ documentId: todo.id,
data: todo,
).catchError((e) {
// ... handle errors
});
setState(() {
- todos.add(newTodo);
+ todos.add(todo);
isLoading = false;
});
}
From 759ffbb2d1a3888dfc275a0aa45caf7052de9a30 Mon Sep 17 00:00:00 2001
From: "Vincent (Wen Yu) Ge"
Date: Mon, 15 May 2023 19:54:05 +0000
Subject: [PATCH 24/30] Relative linkes
---
app/views/docs/offline.phtml | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/app/views/docs/offline.phtml b/app/views/docs/offline.phtml
index e29158ae2..77ee2fc5c 100644
--- a/app/views/docs/offline.phtml
+++ b/app/views/docs/offline.phtml
@@ -8,7 +8,7 @@ use Appwrite\Utopia\View;
Offline Support allows your client apps to continue functioning without an internet connection. Mobile devices frequently encounter situations where internet access becomes unstable or temporarily unavailable, like going through tunnels, getting on airplanes and subways, or going in and out of Wi-Fi range. Offline Support keeps your users engaged when transitioning through these real-life situations.
-When Should I Enable Offline Support?
+When Should I Enable Offline Support?
You should consider enabling Offline Support if you expect the device running your application to experience short periods without a network connection, like going on an airplane or through a tunnel.
@@ -16,12 +16,12 @@ use Appwrite\Utopia\View;
Offline Support can't help you if the app's data needs to remain up to date with frequent updates or if write requests need to be processed immediately. If you expect your app to be offline for days or weeks, you may need to find alternative solutions.
-Enable Offline Support
+Enable Offline Support
Breaking Changes
Enabling Offline Support introduces breaking changes to the asynchronous operation behavior of Client SDKs. Existing projects must be updated.
-
+
Toggle Persistency
@@ -42,7 +42,7 @@ use Appwrite\Utopia\View;
client.setOfflineCacheSize(40000);
When Offline Support is enabled, Appwrite allows you to query and write data by adding a cache layer.
@@ -65,7 +65,7 @@ When Offline Support is enabled, Appwrite allows you to query and write data by -When Offline Support is enabled, write operations only resolve after the server accepts the request. Requests made with the Client SDK may block code execution until network connection is available again.
@@ -126,7 +126,7 @@ When Offline Support is enabled, Appwrite allows you to query and write data by } -With Offline Support enabled, your app can continue sending requests to Appwrite APIs while offline through a cache when offline. Read requests will be fetched from the locally cached data. Write requests will be queued and executed once the device is online again. This can lead to conflicts if another device makes a different change.
From 6648bffaa15deb5d3ba6b4ed09267ff6a69849d3 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge"
From bb3ccb82af08ff76d6f323737530cc545c657bff Mon Sep 17 00:00:00 2001
From: "Vincent (Wen Yu) Ge"
Writes will update the local cache first. If the device is online, the changes will be sent to Appwrite immediately. If the device is not connected to the internet, the operation will be queued and synced to Appwrite when internet is available again.
- + +When Offline Support is enabled, write operations only resolve after the server accepts the request. Requests made with the Client SDK may block code execution until network connection is available again.
- + + +You should optimistically update your app's local state after a write operation. Once you're online again, the write will be synced with your Appwrite project, which will be fetched when you app restarts in the future.
From cdeff777cc7ed4bb015300145f2eba97d4c29097 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge"When Offline Support is enabled, write operations only resolve after the server accepts the request. Requests made with the Client SDK may block code execution until network connection is available again.
- - + +
You should optimistically update your app's local state after a write operation. Once you're online again, the write will be synced with your Appwrite project, which will be fetched when you app restarts in the future.
From d1f66fb005313417161cbda0638ec6493af81d17 Mon Sep 17 00:00:00 2001
From: "Vincent (Wen Yu) Ge"
When Offline Support is enabled, write operations only resolve after the server accepts the request. Requests made with the Client SDK may block code execution until network connection is available again.
- - + +
You should optimistically update your app's local state after a write operation. Once you're online again, the write will be synced with your Appwrite project, which will be fetched when you app restarts in the future.
From 68a8f4fdfac8f964289db5ef1bbce5f184166c61 Mon Sep 17 00:00:00 2001
From: "Vincent (Wen Yu) Ge"
Writes will update the local cache first. If the device is online, the changes will be sent to Appwrite immediately. If the device is not connected to the internet, the operation will be queued and synced to Appwrite when internet is available again.
- - +setParam('srcLight', '/images-ee/docs/offline-write-uml-light.png') + ->setParam('srcDark', '/images-ee/docs/offline-write-uml-dark.png') + ->setParam('alt', 'UML diagram depicting offline write operations.') + ->setParam('description', 'UML diagram depicting offline write operations.') + ->setParam('width', '100%') + ->render(); +?>When Offline Support is enabled, write operations only resolve after the server accepts the request. Requests made with the Client SDK may block code execution until network connection is available again.
- - +setParam('srcLight', '/images-ee/docs/offline-async-uml-light.png') + ->setParam('srcDark', '/images-ee/docs/offline-async-uml-dark.png') + ->setParam('alt', 'UML diagram depicting offline cache in async operations.') + ->setParam('description', 'UML diagram depicting offline cache in async operations.') + ->setParam('width', '100%') + ->render(); +?>You should optimistically update your app's local state after a write operation. Once you're online again, the write will be synced with your Appwrite project, which will be fetched when you app restarts in the future. diff --git a/app/views/general/image.phtml b/app/views/general/image.phtml index 22513b85f..fbb268416 100644 --- a/app/views/general/image.phtml +++ b/app/views/general/image.phtml @@ -1,13 +1,22 @@ getParam('srcLight', ''); $srcDark = $this->getParam('srcDark', $srcLight); -$alt = $this->getParam('alt', 'Screenshot'); +$description = $this->getParam('description', ''); +$width = $this->getParam('width', ''); $description = $this->getParam('description', ''); ?>