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

simple-shared-state

v5.0.1

Published

Easily share state between components using a no-frills observable object API

Downloads

27

Readme

Simple Shared State

Redux is verbose. SimpleSharedState is brief.

Status

SimpleSharedState is still relatively experimental. Versions are following semver, but the version being greater than 1.0 doesn't mean it's considered production ready just yet. Please review the project source and tests to determine if it's viable for your project. More elaborate tests are needed to test SimpleSharedState performance against Redux.

Get It

npm install simple-shared-state

If using script tags:

<script src="https://unpkg.com/simple-shared-state"></script>
<script>
  const store = new SimpleSharedState.Store({});
</script>

Support for Internet Explorer

Use dist/simple-shared-state.es5.umd.js. For example:

<script src="https://unpkg.com/simple-shared-state/dist/simple-shared-state.es5.umd.js"></script>

Basic Use

First create a store.

import { Store } from "simple-shared-state";

const initialState = {
  user: {
    name: "Alice",
    slogan: "simple-shared-state makes apps fun again",
  },
};
const actions = () => ({
  changeSlogan: (newSlogan) => ({
    user: {
      slogan: newSlogan,
    },
  }),
});
const store = new Store(initialState, actions);

Then create a watcher. Don't worry about error handling in selectors, just return the state that you want.

const selector = (state) => state.user;

store.watch(selector, (state) => {
  console.log("user snapshot:", state);
});

Then call your action to update state and trigger the watch handler.

store.actions.changeSlogan("simple-shared-state is better than cat memes");
// 'user snapshot:' { name: 'Alice', slogan: 'simple-shared-state is better than cat memes' }

Redux Devtools

Works with devtools, of course. Just pass in the reference like this:

const store = new Store(initialState, actions, window.__REDUX_DEVTOOLS_EXTENSION__);

React Hooks

useSimpleSharedState

Future Work

  • Fix redux devtools integration
  • Add support for async/await in action creators
  • Support typescript types
  • Explore potential to optimize selector processing for very large state trees