From 5ec5d0c91c0726ed74b0cb8772d992ae478625b8 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 13 Sep 2020 18:43:44 -0400 Subject: Database change event (#826) * Add api.triggerDatabaseUpdated and yomichan.on('databaseUpdated') * Update databaseUpdated event usage --- ext/mixed/js/api.js | 4 ++++ ext/mixed/js/yomichan.js | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js index fce8fbee..ad5846fa 100644 --- a/ext/mixed/js/api.js +++ b/ext/mixed/js/api.js @@ -197,6 +197,10 @@ const api = (() => { return this._invoke('getDefinitionAudio', {sources, expression, reading, details}); } + triggerDatabaseUpdated(type, cause) { + return this._invoke('triggerDatabaseUpdated', {type, cause}); + } + // Invoke functions with progress deleteDictionary(dictionaryName, onProgress) { diff --git a/ext/mixed/js/yomichan.js b/ext/mixed/js/yomichan.js index 217721bd..47c63e38 100644 --- a/ext/mixed/js/yomichan.js +++ b/ext/mixed/js/yomichan.js @@ -56,11 +56,12 @@ const yomichan = (() => { this._isBackendReadyPromiseResolve = resolve; this._messageHandlers = new Map([ - ['isReady', {async: false, handler: this._onMessageIsReady.bind(this)}], - ['backendReady', {async: false, handler: this._onMessageBackendReady.bind(this)}], - ['getUrl', {async: false, handler: this._onMessageGetUrl.bind(this)}], - ['optionsUpdated', {async: false, handler: this._onMessageOptionsUpdated.bind(this)}], - ['zoomChanged', {async: false, handler: this._onMessageZoomChanged.bind(this)}] + ['isReady', {async: false, handler: this._onMessageIsReady.bind(this)}], + ['backendReady', {async: false, handler: this._onMessageBackendReady.bind(this)}], + ['getUrl', {async: false, handler: this._onMessageGetUrl.bind(this)}], + ['optionsUpdated', {async: false, handler: this._onMessageOptionsUpdated.bind(this)}], + ['databaseUpdated', {async: false, handler: this._onMessageDatabaseUpdated.bind(this)}], + ['zoomChanged', {async: false, handler: this._onMessageZoomChanged.bind(this)}] ]); } @@ -290,6 +291,10 @@ const yomichan = (() => { this.trigger('optionsUpdated', {source}); } + _onMessageDatabaseUpdated({type, cause}) { + this.trigger('databaseUpdated', {type, cause}); + } + _onMessageZoomChanged({oldZoomFactor, newZoomFactor}) { this.trigger('zoomChanged', {oldZoomFactor, newZoomFactor}); } -- cgit v1.2.3