aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/client.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-05-05 21:36:50 -0700
committerAlex Yatskov <alex@foosoft.net>2016-05-05 21:36:50 -0700
commitf1e078c7d8fa09e8471e66b245afb80a1b78cc6b (patch)
treee6dd29654f7bbf3771d57b40e9d342a3b07cd823 /ext/fg/js/client.js
parentcc33a30b5eb531651346a407040f65b9ebb8a6c8 (diff)
Removing flicker
Diffstat (limited to 'ext/fg/js/client.js')
-rw-r--r--ext/fg/js/client.js27
1 files changed, 23 insertions, 4 deletions
diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js
index e7300874..14c0a95f 100644
--- a/ext/fg/js/client.js
+++ b/ext/fg/js/client.js
@@ -27,6 +27,7 @@ class Client {
this.enabled = false;
this.options = {};
this.definitions = null;
+ this.sequence = 0;
this.fgRoot = chrome.extension.getURL('fg');
chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this));
@@ -105,16 +106,21 @@ class Client {
if (length === 0) {
this.hidePopup();
} else {
+ const sequence = this.sequence++;
range.setLength(length);
bgRenderText(
- {defs: definitions, root: this.fgRoot, options: this.options},
+ {defs: definitions, root: this.fgRoot, options: this.options, sequence: sequence},
'term-list.html',
(content) => {
this.definitions = definitions;
this.showPopup(range, content);
+
bgCanAddNotes(definitions, (states) => {
if (states !== null) {
- states.forEach((state, index) => this.popup.sendMessage('setActionState', {index: index, state: state}));
+ states.forEach((state, index) => this.popup.sendMessage(
+ 'setActionState',
+ {index: index, state: state, sequence: sequence}
+ ));
}
});
}
@@ -127,17 +133,30 @@ class Client {
const state = {};
state[mode] = false;
- this.popup.sendMessage('setActionState', {index: index, state: state});
+ this.popup.sendMessage(
+ 'setActionState',
+ {index: index, state: state, sequence: this.sequence}
+ );
}
actionDisplayKanji(kanji) {
bgFindKanji(kanji, (definitions) => {
+ const sequence = this.sequence++;
bgRenderText(
- {defs: definitions, root: this.fgRoot, options: this.options},
+ {defs: definitions, root: this.fgRoot, options: this.options, sequence: sequence},
'kanji-list.html',
(content) => {
this.definitions = definitions;
this.popup.setContent(content, definitions);
+
+ bgCanAddNotes(definitions, (states) => {
+ if (states !== null) {
+ states.forEach((state, index) => this.popup.sendMessage(
+ 'setActionState',
+ {index: index, state: state, sequence: sequence}
+ ));
+ }
+ });
}
);
});