-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Description
I see that LiveQuery uses the ember-destroyable-polyfill, and that all queries get destroyed when the cache itself gets destroyed.
But it seems likely that many live queries have a lifetime shorter than that, like being associated with a component. In my own experiments, I have a utility like this:
// app/lib/query.js
import { associateDestroyableChild } from '@ember/destroyable';
import { getOwner } from '@ember/application';
export function liveQuery(parent, query) {
let records = getOwner(parent).lookup('service:store').cache.liveQuery(query);
associateDestroyableChild(parent, records);
return records;
}That I use like this:
// app/components/my-component.js
import { liveQuery } from '../lib/query';
export default class extends Component {
observations = liveQuery(this, (qb) =>
qb.findRecords('observation').sort('-time')
);
}This ensures that the live query is destroyed whenever its parent component is destroyed.
Is there a better built-in solution? Should something like this utility be added to ember-orbit?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels