npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

statelit

v0.1.1

Published

State management library for Lit, enabling easy state sharing across components.

Readme

StateLit

StateLit is a lightweight state management library designed for LitElement-based applications. It facilitates a structured approach to defining, updating, and sharing state across components. By decoupling state and logic from your components, StateLit aids in organizing your code in a clean, scalable, and maintainable manner, right out of the box.

Features

  • State Sharing Across Components: State can be shared across multiple components effortlessly. When one component updates the state, all other components using that state will re-render to reflect the changes.

Dependencies

  • StateLit depends on Lit ^3.0.0

Installation

npm i statelit

Getting Started

Start by defining a state class for each distinct part of your application's state. Each state class should extend LitState and initialize its state in the constructor.

// counterState.ts
import { LitState } from "statelit";

interface ICounterState {
  counter: number;
}

export class CounterState extends LitState<ICounterState> {
  constructor() {
    super({ counter: 0 });
  }
}

export const counterState = new CounterState();

Creating Components

Components that need to interact with a state should extend StatefulLitElement and pass the state instance to the super constructor.

// counter-component.ts
import { html } from "lit";
import { customElement } from "lit/decorators.js";
import { counterState } from "./counterState";
import { StatefulLitElement } from "statelit";

@customElement("counter-component")
class CounterComponent extends StatefulLitElement<typeof counterState.state> {
  constructor() {
    super(counterState);
  }

  render() {
    return html`
      <div>
        <button
          @click=${() =>
            counterState.update({ counter: this.state.counter - 1 })}
        >
          -
        </button>
        ${this.state.counter}
        <button
          @click=${() =>
            counterState.update({ counter: this.state.counter + 1 })}
        >
          +
        </button>
      </div>
    `;
  }
}

Example of State Sharing Across Components

// counter-display.ts
import { html } from "lit";
import { customElement } from "lit/decorators.js";
import { counterState } from "./counterState";
import { StatefulLitElement } from "statelit";

@customElement("counter-display")
class CounterDisplay extends StatefulLitElement<typeof counterState.state> {
  constructor() {
    super(counterState);
  }

  render() {
    return html`<div>Counter: ${this.state.counter}</div>`;
  }
}

Creating Controllers

For complex logic or actions that affect the state, it's a good practice to create a controller. Controllers encapsulate the logic for manipulating the state, making it easier to manage and test.

// counter-controller.ts
import { counterState } from "./counterState";

class CounterController {
  increment() {
    const currentCount = counterState.state.counter;
    counterState.update({ counter: currentCount + 1 });
  }

  decrement() {
    const currentCount = counterState.state.counter;
    counterState.update({ counter: currentCount - 1 });
  }
}

export const counterController = new CounterController();

Then, update your components to use the controller for state mutations.

// counter-component.ts
// ... other imports ...
import { counterController } from "./counter-controller";

@customElement("counter-component")
class CounterComponent extends StatefulLitElement<typeof counterState.state> {
  // ... rest of the code ...

  render() {
    return html`
      <div>
        <button @click=${counterController.decrement}>-</button>
        ${this.state.counter}
        <button @click=${counterController.increment}>+</button>
      </div>
    `;
  }
}

With StateLit, you can structure your LitElement applications in a clean, organized, and scalable way, making it easier to manage state and logic as your project grows.