zulip/controllers/store-controller.js

23 lines
566 B
JavaScript
Raw Permalink Normal View History

2026-03-04 18:26:43 -08:00
export class StoreController {
constructor(host, store, selector) {
this.host = host
this.store = store
this.selector = selector
host.addController(this)
}
hostConnected() {
this._unsub = this.store.subscribe(
(state) => {
const next = this.selector(state)
if (next !== this.value) {
this.value = next
this.host.requestUpdate()
}
}
)
this.value = this.selector(this.store.getState())
}
hostDisconnected() { this._unsub?.() }
}