Yes, check out LitState (npm package name lit-element-state
).
I created this specially for LitElement. It has the same mindset: simple, small and powerful.
Because it is created specially for LitElement, it integrates very well and therefore the usage is very simple. You make a state object like this:
import { LitState, stateVar } from 'lit-element-state';
class MyState extends LitState {
@stateVar() myCounter = 0;
}
export const myState = new MyState();
Usage without @decorators, look here.
Then you can use the state in your components like this:
import { LitElement, html } from 'lit-element';
import { observeState } from 'lit-element-state';
import { myState } from './my-state.js';
class MyComponent extends observeState(LitElement) {
render() {
return html`
<h1>Counter: ${myState.counter}</h1>
<button @click=${() => myState.counter++}></button>
`;
}
}
When you add the observeState()
mixin to your component, the component will automatically re-render when any stateVar
they use changes. You can do this with any amount of component and states and it will all automatically stay synchronized thanks to the observeState()
mixin.