Description
Current Limitation
When developing applications using Parse, you want to sync the App with the Server when the App is re-opened after being killed, shut down or restored from the background.
You need a Query to obtain the most current data and subscribe to a LiveQuery to receive real-time updates while the application is in use.
In complex apps with multiple collections, a large number of Query + LiveQuery combinations are necessary every time the app is restored from the background, requiring several REST calls and a WebSocket connection.
Feature / Enhancement Description
It should be possible to run Queries through a LiveQueryClient, and/or to request query results along with LiveQuery subscription to enable syncing collections and subscribing to LiveQueries with a single WebSocket connection.
We believe that this improvement makes a difference. It's easy to develop and maintain, with minimal changes to the Parse Server and client SDKs.
This is not a breaking change, it is fully retrocompatible, and existing apps can be improved easily.
EDIT Apr 30:
It would be beneficial to have the option to use WebSocket for all requests, including Queries, Saves, Cloud Functions, and all CRUD operations.
Example Use Case
Imagine a complex TODO mobile app with six collections: boards, tasks, goals, categories, tags, and users.
Every time the user opens the App after from background, especially after being offline, you need to run six Parse Queries and subscribe to them.
Each of the six queries is an HTTP/REST API call, while all LiveQueries travel on a single Websocket connection.
Current Approach:
const tasks = getTasksFromLocalDb();
const query = new Parse.Query('Tasks');
query.greaterThan("updatedAt", getLastTimeOpenedApp());
// This is the standard (and only) way so far to retrieve objects.
const results = await query.find(); // For each Query, the SDK triggers the REST API Call we want to avoid.
results.forEach(task => tasks[task.id] = task);
const subscription = await query.subscribe();
subscription.on('create', task => tasks[task.id] = task);
Possible Alternative 1:
Get query results leveraging the subscription
subscription.on('result', task => tasks[task.id] = task);
subscription.find(); // or subscription.first(); or getResults() or runQuery(), or any other naming that makes sense.
Possible Alternative 2:
Allow running any query from a LiveQueryClient. This potentially enables developers to run queries through WebSocket, detached from a subscription.
const client = new LiveQueryClient({ ... });
const querySubscription = client.querySubscribe(query);
querySubscription.on('result', task => tasks[task.id] = task);
Ideally, both alternatives 1 and 2 should be developed, with one serving as a shortcut for the other.
3rd Party References
Firebase onSnapshot
event.