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 🙏

© 2024 – Pkg Stats / Ryan Hefner

lit-sm

v1.0.3

Published

A simple state management library for lit

Downloads

5

Readme

lit-sm: A Simple State Management Library for Lit

Overview

lit-sm is a lightweight state management library designed to work seamlessly with the Lit library (formerly known as LitElement). It provides a straightforward method to integrate shared state management into your Lit-based web components. This README will guide you through the installation, usage, and key features of lit-sm.

Installation

You can easily integrate lit-sm into your project by following these simple steps:

  1. Install the package using npm or yarn:
   npm install lit-sm
   # or
   yarn add lit-sm
  1. Import the necessary functions and classes in your project:
import { createSharedStateMixin } from 'lit-sm';

Getting Started

lit-sm provides a mixin that you can use to add shared state functionality to your LitElement-based components. Here's how you can get started:

Define your initial state in a separate module (e.g., state.ts):

import { createSharedStateMixin } from 'lit-sm';
import { v4 as uuidv4 } from 'uuid';

// Define the initial state interface
interface sharedState {
  x: number;
  //...
}

const initialState: sharedState = {
  x: 0
  //...
};

// Export the shared state mixin
export const SharedTestStateMixin = createSharedStateMixin(initialState);

Import and use the shared state mixin in your LitElement components (e.g., element.ts):


import { LitElement, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { SharedTestStateMixin } from './state.js';

@customElement('root-element')
export class RootElement extends SharedTestStateMixin(LitElement) {

  @property()
  lit_sm_storage = 'test';

  render() {
  return html`
        <div id="rootElement">
          <div>${this.sharedState.x}</div>
          <button
            @click=${() => this.sharedState.x++}>
            increment
          </button>
        </div>
    `;
  }
}

declare global {
  interface HTMLElementTagNameMap {
    'root-element': RootElement;
  }
}

Key Features

Shared State

lit-sm allows you to easily share state across components that use the same mixin. This means that you can manage and synchronize state between different components without complex setup.

State Persistence

You can enhance your components by adding the lit_sm_storage property to them. When this property is provided, the shared state will be automatically saved and loaded from it. This feature is especially usefull when developing widgets for the webwriter.

Disabling Declaration Files (TypeScript Users)

If you are using TypeScript and want to use lit-sm, make sure to disable the generation of declaration files in your tsconfig.json:

{
  "compilerOptions": {
    "declaration": false
    //...
  }
}

Unfortunately, typescript is not able to generate declaration files when using this library. This is due to the fact that the mixin is dynamically generated at runtime. Maybe this will be possible in a future version of TypeScript. (tested version: 5.2)

License

lit-sm is licensed under the MIT License or the ISC License, whichever is more suitable for your use case.

Contributing

If you want to contribute to this project, feel free to open an issue or submit a pull request. The docs for developers can be found here.

Copyright

© Luis Kugel 2023