I’m wondering if anyone knows there’s a local query method that can be used to compare a query to a saved object.
Example:
const obj = await new Parse.Query("Test").first();
const query = new Parse.Query("Test").equalTo("foo", "bar");
query.isInQuery(obj) // some method that tells me whether obj is in the query
At the moment my workaround is (not ideal as it creates a network request):
That’s an interesting question. Your question “how to know whether an object matches a query” seems to be just a different phrasing for “how to know whether a query matches an object”. In other words you want to change the data source from the database to an in-memory list of objects.
let objects = [];
let latestQuery = null;
const getObjects = async () => {
latestQuery = new Parse.Query("Test").equalTo("condition1", true) // more conditions
objects = await latestQuery.find();
}
filter.on("change", getObjects); // this is called every time a button is clicked
const subscription = await new Parse.Query("Test").equalTo("user", user).subscribe();
subscription.on("update", (obj) => {
if (latestQuery.matchesObject(obj)) { // this method doesn't exist, wondering if there's something like this
objects.push(obj);
}
});
The alternative is to unsubscribe and re-subscribe with the additional query constraints, but there is a risk that an update event will not fire inbetween unsubscribe and subscribe, and there are other events that I would like to listen to as well.