-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathapplication.js
More file actions
65 lines (55 loc) · 1.45 KB
/
application.js
File metadata and controls
65 lines (55 loc) · 1.45 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
import { defer } from 'rsvp';
import { assert } from '@ember/debug';
import { isEmpty } from '@ember/utils';
import { Adapter } from 'ember-pouch';
import PouchDB from 'dummy/pouchdb';
import config from 'dummy/config/environment';
function createDb() {
let localDb = config.emberPouch.localDb;
assert('emberPouch.localDb must be set', !isEmpty(localDb));
let db = new PouchDB(localDb);
if (config.emberPouch.remote) {
let remoteDb = new PouchDB(config.emberPouch.remoteDb);
db.sync(remoteDb, {
live: true,
retry: true,
});
}
return db;
}
export default class ApplicationAdapter extends Adapter {
constructor(owner, args) {
super(owner, args);
this.db = createDb();
}
_init(store, type) {
type.eachRelationship((name, rel) => {
rel.options.async = config.emberPouch.async;
if (rel.kind === 'hasMany') {
rel.options.save = config.emberPouch.saveHasMany;
}
});
if (super._init) {
return super._init(...arguments);
}
}
onChangeListenerTest = null;
async onChange() {
if (super.onChange) {
await super.onChange(...arguments);
}
if (this.onChangeListenerTest) {
this.onChangeListenerTest(...arguments);
}
}
waitForChangeWithID(id) {
let defered = defer();
this.onChangeListenerTest = (c) => {
if (c.id === id) {
this.onChangeListenerTest = null;
defered.resolve(c);
}
};
return defered.promise;
}
}