4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-12 02:05:51 +00:00
qortal-ui/core/translate/directives/lang-changed-base.js
2023-11-25 16:25:19 +01:00

40 lines
915 B
JavaScript

import { AsyncDirective } from 'lit/async-directive.js'
import { listenForLangChanged } from '../util.js'
export class LangChangedDirectiveBase extends AsyncDirective {
constructor() {
super(...arguments)
this.langChangedSubscription = null
this.getValue = (() => "")
}
renderValue(getValue) {
this.getValue = getValue
this.subscribe()
return this.getValue()
}
langChanged(e) {
this.setValue(this.getValue(e))
}
subscribe() {
if (this.langChangedSubscription == null) {
this.langChangedSubscription = listenForLangChanged(this.langChanged.bind(this))
}
}
unsubscribe() {
if (this.langChangedSubscription != null) {
this.langChangedSubscription()
}
}
disconnected() {
this.unsubscribe()
}
reconnected() {
this.subscribe()
}
}