attempting to resurrect full beans
This commit is contained in:
parent
bceee7ecf1
commit
a961f387d6
9 changed files with 170 additions and 65 deletions
23
controllers/store-controller.js
Normal file
23
controllers/store-controller.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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?.() }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue