Orbit

https://orbitjs.com/docs/getting-started

$ yarn add @orbit/coordinator @orbit/data @orbit/jsonapi @orbit/memory
import MemorySource from '@orbit/memory';
import JSONAPISource from '@orbit/jsonapi';
import Coordinator, {
  RequestStrategy,
  SyncStrategy,
  EventLoggingStrategy,
  LogTruncationStrategy,
} from '@orbit/coordinator';
import schema from './schema';

const memory = new MemorySource({schema});

memory.requestQueue.on('fail', () => {
  memory.requestQueue.skip();
});

let storeReady;

const remote = new JSONAPISource({
  schema,
  name: 'remote',
  host: baseURL,
});

remote.requestQueue.on('fail', () => {
  remote.requestQueue.skip();
});

const coordinator = new Coordinator({
  sources: [memory, remote],
});

// Query the remote server whenever the store is queried
coordinator.addStrategy(
  new RequestStrategy({
    source: 'memory',
    on: 'beforeQuery',
    target: 'remote',
    action: 'query',
    blocking: true,
  }),
);

// Update the remote server whenever the store is updated
coordinator.addStrategy(
  new RequestStrategy({
    source: 'memory',
    on: 'beforeUpdate',
    target: 'remote',
    action: 'update',
    blocking: true,
  }),
);

// Sync all changes received from the remote server to the store
coordinator.addStrategy(
  new SyncStrategy({
    source: 'remote',
    target: 'memory',
    blocking: true,
  }),
);

// log events to console
coordinator.addStrategy(new EventLoggingStrategy());

// truncate transform logs
coordinator.addStrategy(
  new LogTruncationStrategy({
    sources: ['memory', 'remote'],
  }),
);

export default memory;