Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@lit-app/state
Advanced tools
@lit-app/state is a global state management, integrating with lit web-components.
There are plenty options available for state management, so why yet another one?
import { State, StateController, property } from "@lit-app/state";
import { LitElement } from "lit";
// declare some state
class MyState extends State {
@property({value: 'Bob'}) name
}
const myState = new MyState()
// declare a component
class StateEl extends LitElement {
// StateController is a Reactive Controller binding myState with the element
state = new StateController(this, myState)
override render() {
return html`
<div>This will be updated when the state changes: ${myState.name}</div>
`;
}
}
// changing the state will reflect in the template
myState.name = 'Alice'
Very simple demo on lit.dev playground.
State
extends EventTarget and dispatches a StateEvent
when one of its properties changes.
StateController
listens for a StateEvent
emited by a bound state. By default, it calls a requestUpdate on the lit element; the callback function is configurable.
Decorators augment the capacity of state properties:
Bind a state property with localStorage, so that its value can persist.
import { State, property, storage } from "@lit-app/state";
class MyState extends State {
@storage({key: 'localstorage_key'})
@property({value: 'Bob'}) name
}
const myState = new MyState()
Init a state property value with an URL parameter, and also persist it to localStorage.
import { State, property, storage } from "@lit-app/state";
class MyState extends State {
@query({parameter: 'name-parameter'})
@storage({key: 'localstorage_key'})
@property({value: 'Bob'}) name
}
const myState = new MyState()
Hook decorator allows to configure state properties for the use of other third parties
import { State, property, hook } from "@lit-app/state";
class MyState extends State {
@hook('firebase', {path: 'a/path/to/be/consumed'})
@property({value: 'Bob'}) name
}
const myState = new MyState()
> pnpm add @lit-app/state
or
> npm install @lit-app/state
FAQs
state management for lit-app
The npm package @lit-app/state receives a total of 913 weekly downloads. As such, @lit-app/state popularity was classified as not popular.
We found that @lit-app/state demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.