Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { JSONAPISerializer } from '@orbit/jsonapi';
import { api as apiEnv } from '@env';
import { defaultHeaders } from '@lib/fetch';
import { schema, keyMap } from './schema';
export const serializer = new JSONAPISerializer({ schema, keyMap });
// DEBUG!
// Orbit.fetch = (...args) => {
// console.log(args);
// return fetch(...args);
// };
export function defaultOptions() {
return {
sources: {
remote: {
settings: {
...defaultSourceOptions(),
},
},
},
create(injections = {}) {
// Use `fetch` implementation from `ember-fetch`
Orbit.fetch = fetch;
injections.name = 'remote';
return new JSONAPISource(injections);
}
};
constructor() {
this.currentSchema = currentSchema
this.schema = new Schema(currentSchema)
this.remote = new JSONAPISource({ schema: this.schema, name: 'remote', host: 'http://localhost:5000/api/v2/storefront' })
this.coordinator = new Coordinator()
this.store = new Store({ schema: this.schema, name: 'store' })
this.coordinator.addSource(this.store)
this.coordinator.addSource(this.remote)
this.coordinator.addStrategy(new RequestStrategy({
source: 'store',
on: 'beforeQuery',
target: 'remote',
action: 'pull',
blocking: true
}))
this.coordinator.addStrategy(new SyncStrategy({
source: 'remote',