Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Orbit strategy with filter based on whether in cache or not
import {
RequestStrategy,
} from '@orbit/coordinator';
export default {
create() {
return new RequestStrategy({
name: 'store-yapp-api-query-blocking',
source: 'store',
on: 'beforeQuery',
target: 'yapp-api',
action: 'pull',
blocking: true,
filter: onlySingleRecordLookupsThatAreNotAlreadyCached,
catch(e) {
console.log('error performing yapp-api.pull', e); // eslint-disable-line
this.source.requestQueue.skip();
this.target.requestQueue.skip();
throw e;
}
});
}
};
function onlySingleRecordLookupsThatAreNotAlreadyCached(query) {
if (query.expression.op !== 'findRecord') {
return false;
}
return !this.source.cache.getRecordSync(query.expression.record);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment