aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/yomichan.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-10-21 20:08:16 -0700
committerAlex Yatskov <alex@foosoft.net>2016-10-21 20:08:16 -0700
commit25a8f4fb6820cbd4be9286c85a00165ce01c0704 (patch)
tree5a4dc95e0753488e145014c6029958416552701c /ext/bg/js/yomichan.js
parent3962a9cb1968c1f5610cef1cb515ab7a0f8caa2d (diff)
Cleanup
Diffstat (limited to 'ext/bg/js/yomichan.js')
-rw-r--r--ext/bg/js/yomichan.js32
1 files changed, 8 insertions, 24 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 4ba44588..3091e503 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -235,27 +235,15 @@ class Yomichan {
}
api_getOptions({callback}) {
- loadOptions().then(result => {
- callback({result});
- }).catch(error => {
- callback({error});
- });
+ promiseCallback(loadOptions(), callback);
}
api_findKanji({text, callback}) {
- this.translator.findKanji(text).then(result => {
- callback({result});
- }).catch(error => {
- callback({error});
- });
+ promiseCallback(this.translator.findKanji(text), callback);
}
api_findTerm({text, callback}) {
- this.translator.findTerm(text).then(result => {
- callback({result});
- }).catch(error => {
- callback({error});
- });
+ promiseCallback(this.translator.findTerm(text), callback);
}
api_renderText({template, data, callback}) {
@@ -264,11 +252,7 @@ class Yomichan {
api_addDefinition({definition, mode, callback}) {
const note = this.formatNote(definition, mode);
- this.anki.addNote(note).then(result => {
- callback({result});
- }).catch(error => {
- callback({error});
- });
+ promiseCallback(this.anki.addNote(note), callback);
}
api_canAddDefinitions({definitions, modes, callback}) {
@@ -279,7 +263,7 @@ class Yomichan {
}
}
- this.anki.canAddNotes(notes).then(raw => {
+ const promise = this.anki.canAddNotes(notes).then(raw => {
const states = [];
for (let resultBase = 0; resultBase < raw.length; resultBase += modes.length) {
const state = {};
@@ -290,10 +274,10 @@ class Yomichan {
states.push(state);
}
- callback({result: states});
- }).catch(error => {
- callback({error});
+ return states;
});
+
+ promiseCallback(promise, callback);
}
}