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

lit-element-simple-context

v1.2.7

Published

Webcomponent lit-element-context following open-wc recommendations

Readme

lit-element-context state manager

It supposed to be a simple context provider but somehow it became a store 🪦

It's a simple state manager for lit-element. I needed something like redux, but something less complicated. It implements a store, and provides a method to set and update properties in the store.

On every property update, the components get a new data injected into them through props, and as we know, components are rerendered if the properties are changed.

you can find a working example in the test/components folder.

New features

Version 1.2.5

  • [x] changed "module" to "ES6"

Version 1.2.1

  • [x] added generic types for state

Version 1.2.0

  • [x] added TS support for lit-ts

Version 1.1.1

  • [x] improved redux devtools usage

Version 1.1.0

  • [x] removed deprecated methods

  • [x] improved register and deregister methods on lifecycle

  • [x] remove component from observers when disconnected from DOM

Version 1.0.13

  • [x] added meta information to the store init method

Version 1.0.12

  • [x] added iframe support

Version 1.0.11

  • [x] added devtools support

Version 1.0.9

  • [x] rename prop with contextKey attribute

Version 1.0.6

  • [x] fromContext attribute in the properties getter

Version 1.0.5

  • [x] actions and async actions
  • [x] setProps method to set multiple values at the same time

Usage

init the context where ever you want

import context from 'lit-element-simple-context';

context.init({propName: someval, propName2: {nestedData: []} });

You can use devtools to debug store, pass true as a second parameter to the init method.

import context from 'lit-element-simple-context';

context.init({...}, true);

You can pass devtools options, like store instance name, as third parameter to the init method. Watch devtools-options.d.ts for available options.

import context from 'lit-element-simple-context';

context.init({...}, true, { name: 'lit context store' });

connect a lit component to the context in JS

import { LitElement } from 'lit';
import context from 'lit-element-simple-context';

class MyLitComponent extends LitElement {}

window.customElements.define('my-lit-component', context.connect(MyLitComponent));

connect a lit component to the context in TS

import { LitElement, property } from 'lit';
import { Context } from 'lit-element-simple-context';

type MyContextType = {};
const context = new Context<MyContextType>();

@customElement('my-lit-component')
@context.connectElement()
export class MyLitComponent extends LitElement {}

To specify the props you need from context in your component, you should set fromContext attribute in the properties getter. If the lit property name is different what you use in the store, you can specify it with contextKey attribute

class MyLitComponent extends LitElement {
  static get properties() {
    return {
      somepropFromContext: {type: Number, fromContext: true},
      renamedProp: {type: String, fromContext: true, contextKey: 'somepropInTheStore'}
    }
  }
}

You can do it in TS as well with either using the default typings or your custom state type:

import { LitElement } from 'lit';
import context from 'lit-element-simple-context';

@customElement('my-lit-component')
@context.connectElement()
export class MyLitComponent extends LitElement {

  @property({fromContext: true})
  somepropFromContext = '';
  
}

With custom types:

import { LitElement, property } from 'lit';
import { Context } from 'lit-element-simple-context';

type MyContextType = {};
const context = new Context<MyContextType>();

@customElement('my-lit-component')
@context.connectElement()
export class MyLitComponent extends LitElement {

  @property({fromContext: true})
  somepropFromContext = '';
  
}

change a value in the store once the component is connected to the store

this.setProp('somepropFromContext2', 0);

change a value in the store if the component is not connected to the store

import context from 'lit-element-simple-context';

context.setProp('someprop', context.state.someprop + 1);

You can use actions (and async actions as well) instead of setProp method calls.

// actions.js
import context from 'lit-element-simple-context';

export const incrementBy = context.action((state, value) => ({someprop: state.someprop + value}));

export const asyncAction = context.asyncAction(async (_, value1, value2) => ({ value1, value2}));


// some-other-file.js
import { asyncAction, incrementBy } from './actions.js';

async function foo() {
  await asyncAction('foo', 'bar');

  incrementBy(1);
}

that's it!! there is no need of tons of boilerplate code and every component gets the fresh data on change.

Testing with Web Test Runner

To run the suite of Web Test Runner tests, run

yarn test

To run the tests in watch mode

yarn test:watch

Tooling configs

For most of the tools, the configuration is in the package.json to reduce the amount of files in your project.

If you customize the configuration a lot, you can consider moving them to individual files.

Local Demo with web-dev-server

yarn start

To run a local development server that serves the basic demo located in demo/index.html