-
Notifications
You must be signed in to change notification settings - Fork 117
Conversation
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.
Sounds good so far. Just some tweaks.
Co-authored-by: Steven <1477010+stnguyen90@users.noreply.github.com>
Proposing additions to getting started guides later. |
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 added the content you requested. Let me know if there's anything else you need.
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 can be enabled by setting <code>setOffilnePersistency</code> to true on your SDK's client. | ||
</p> | ||
|
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.
For Flutter, it'll be:
client.setOfflinePersistency(status: true);
app/views/docs/offline.phtml
Outdated
</p> | ||
|
||
<h3>Considerations and Tradeoffs</h3> | ||
[TODO: Code Example] |
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 will be:
client.setOfflineCacheSize(40000); // 40MB
app/views/docs/offline.phtml
Outdated
For example, the code example below will <b>block code execution</b> when the device is offline. | ||
</p> | ||
|
||
[TODO: Show Example, in comments clearly mark that it's ] |
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.
Using await
like:
final document = await databases.createDocument(
databaseId: '[DATABASE_ID]',
collectionId: '[COLLECTION_ID]',
documentId: ID.unique(),
data: {},
);
will block execution.
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.
Updated with more info about state:
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;
});
}
app/views/docs/offline.phtml
Outdated
</p> | ||
|
||
[TODO: Show correct version of example. ] |
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.
To avoid blocking, don't await
final document = databases.createDocument(
databaseId: '[DATABASE_ID]',
collectionId: '[COLLECTION_ID]',
documentId: ID.unique(),
data: {},
);
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.
@stnguyen90 I was really hoping to show an illustrative example where we also show updating local state/ui optimistically to make the point clear.
Is this something we can do?
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.
Updated with more info about state:
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;
});
}
app/views/docs/offline.phtml
Outdated
</p> | ||
<p> | ||
[TODO: Describe resolution behavior + tips if available.] |
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.
When a locally queued request is sent to the server, it will include the timestamp when the request was queued in the X-Appwrite-Timestamp
header. Appwrite will compare that request timestamp with the document's $updatedAt
timestamp and return a status 409 error if the document's $updatedAt
timestamp is newer than the request timestamp. The SDK will revert the changes in the local cache, and then the client can try the request again.
@stnguyen90 I was also thinking if there could be a short, self contained code example we can show at the end? might be cool. |
You wouldn't really put everything in 1 self-contained file so I'm not sure if it's good to show that. Maybe we can link to a repo or something once we have the sample app built? |
Can we add it to the playground app? :OOOO |
@gewenyu99, we plan on updating the todo app to showcase relationships and offline support. |
What does this PR do?
Adds body to offline support PR.
Details to be filled are marked TODO.
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)
Related PRs and Issues
(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)
Have you read the Contributing Guidelines on issues?
(Write your answer here.)