lit-state
lit-state copied to clipboard
Any plan to use lit 2.0 controllers ?
Hey @gitaarik
Just curious to know if there are plans to upgrade to lit 2.0 now that it is on release candidate stage?
Apparently controllers would be perfectly fitted to lit-state : https://lit.dev/docs/composition/controllers/
Hi @christophe-g, sorry I haven't replied to this yet. I haven't looked into this new technology of Lit, and currently don't have much time for it either. I would like to look into it when I have more time, so I'll keep you updated about it. Thanks for the suggestion anyway :).
No problem,
currently don't have much time for it either
I so understand that!
I haven't played with controllers yet, but from what I got, they could (possibly greatly) simplify how lit-state checks state changes and re-trigger a requestUpdate.
I agree with the above, but having played with controllers I’m still using lit-state.
The biggest difference I see between them is that it seems like a controller is almost just an extension of the lit element. Or to put it another way, you have 1 controller for 1 element.
The great advantage of lit-state is that multiple elements can hook into a single state object.
The great advantage of lit-state is that multiple elements can hook into a single state object.
Hmm, I think the idea would be to use the controller(s) as an interface between ONE state object and multiple elements. If that is not possible, forget about my suggestion ; )
Yes, I guess your suggestion would be to use Lit controllers inside LitState?
The idea would be to use a controller instead of a mixin to connect a component to a store:
Translating from the readme example, you could do this:
import {LitElement, html} from 'lit-element';
import {StateController} from 'lit-element-state';
import {myState} from './my-state.js';
class MyComponent extends LitElement {
private _state = new StateController(this);
render() {
return html`
<h1>Counter: ${myState.counter}</h1>
<button @click=${() => myState.counter++}></button>
`;
}
}
but perhaps it would be nice to have a direct connection between a component and the state it uses so you could also pass the state to the controller:
class MyComponent extends LitElement {
private _state = new StateController(this, [myState]);
}