-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrating with newer test waiters system #340
Comments
@ef4 Each of these queues is an Orbit currentSource.requestQueue.on('complete', () => {
// optionally return a promise here if you want to delay future actions of the queue until the promise resolves or errors
}); Remember to cleanup with |
Thanks. Is there a corresponding event for going from empty to active? |
Another event to be aware of is |
Thanks, that set me on the right track. I ended up going with import { buildWaiter } from '@ember/test-waiters';
export function buildOrbitWaiter(label) {
let waiter = buildWaiter(label);
const taskTokens = new WeakMap();
function taskStarted(task) {
let token = waiter.beginAsync();
taskTokens.set(task, token);
}
function taskEnded(task) {
let token = taskTokens.get(task);
if (token) {
waiter.endAsync(token);
}
}
function waitForSource(source) {
source.requestQueue.on('beforeTask', taskStarted);
source.requestQueue.on('task', taskEnded);
source.requestQueue.on('fail', taskEnded);
source.syncQueue.on('beforeTask', taskStarted);
source.syncQueue.on('task', taskEnded);
source.syncQueue.on('fail', taskEnded);
return source;
}
return { waitForSource };
} You use it like: import JSONAPISource from '@orbit/jsonapi';
import { buildOrbitWaiter } from '../lib/orbit-waiter';
let { waitForSource } = buildOrbitWaiter('data-source:rails');
export default {
create(injections = {}) {
return waitForSource(new JSONAPISource(injections));
}
} |
I would like to register a source with ember's test waiter system so that this source is included in the default Ember
settled
state. This seems to work:However, current versions of the ember eslint plugin will complain about this use of
registerWaiter
and push you toward the newer @ember/test-waiters system. That API no longer supports polling like this, and instead wants to wrap each asynchronous operation.Since I would guess most sources don't want to build this in by default, would it be appropriate to emit events from the sources that one could observe in order to notice each time a task is enqueue or resolved? Is there an existing hook?
I'm aware of
waitForSource
, but that serves a different purpose than what I'm trying to do here. Especially for people porting from ember-data, it's very helpful to make a remote source always blocksettled
.The text was updated successfully, but these errors were encountered: