forked from Qortal/qortal-ui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
915 B
40 lines
915 B
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() |
|
} |
|
} |