-
Notifications
You must be signed in to change notification settings - Fork 76
/
__name__.js
52 lines (41 loc) · 1.43 KB
/
__name__.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import config from '<%= dasherizedPackageName %>/config/environment';
import { Adapter } from 'ember-pouch';
import { assert } from '@ember/debug';
import { isEmpty } from '@ember/utils';
import PouchDB from 'pouchdb-core';
import PouchDBFind from 'pouchdb-find';
import PouchDBRelational from 'relational-pouch';
import indexeddb from 'pouchdb-adapter-indexeddb';
import HttpPouch from 'pouchdb-adapter-http';
import mapreduce from 'pouchdb-mapreduce';
import replication from 'pouchdb-replication';
PouchDB.plugin(PouchDBFind)
.plugin(PouchDBRelational)
.plugin(indexeddb)
.plugin(HttpPouch)
.plugin(mapreduce)
.plugin(replication);
export default class ApplicationAdapter extends Adapter {
constructor() {
super(...arguments);
const localDb = config.emberPouch.localDb;
assert('emberPouch.localDb must be set', !isEmpty(localDb));
const db = new PouchDB(localDb);
this.db = db;
// If we have specified a remote CouchDB instance, then replicate our local database to it
if (config.emberPouch.remoteDb) {
let remoteDb = new PouchDB(config.emberPouch.remoteDb);
db.sync(remoteDb, {
live: true,
retry: true
});
}
return this;
}
unloadedDocumentChanged(obj) {
let recordTypeName = this.getRecordTypeName(this.store.modelFor(obj.type));
this.db.rel.find(recordTypeName, obj.id).then((doc) => {
this.store.pushPayload(recordTypeName, doc);
});
}
}