storage.js: Don't try and allow to register events for non-local backends

This commit is contained in:
Johannes Meyer 2019-07-30 08:17:29 +02:00
parent 62d4e73d5a
commit 5849c06314

View File

@ -171,6 +171,10 @@
* @returns {void} * @returns {void}
*/ */
onChange: function(key, callback, context) { onChange: function(key, callback, context) {
if (this.backend !== window.localStorage) {
throw new Error('[Storage] Only the localStorage emits events');
}
var prefixedKey = this.prefixKey(key); var prefixedKey = this.prefixKey(key);
if (typeof Icinga.Storage.subscribers[prefixedKey] === 'undefined') { if (typeof Icinga.Storage.subscribers[prefixedKey] === 'undefined') {
@ -273,7 +277,10 @@
this.storage = storage; this.storage = storage;
this.key = key; this.key = key;
if (storage.backend === window.localStorage) {
storage.onChange(key, this.onChange, this); storage.onChange(key, this.onChange, this);
}
return this; return this;
}, },