New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

simple-shared-state

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-shared-state

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

latest
Source
npmnpm
Version
5.0.1
Version published
Maintainers
1
Created
Source

Simple Shared State

Redux is verbose. SimpleSharedState is brief.

  • Docs: https://simplesharedstate.com
  • Repo: https://github.com/rm-rf-etc/simple-shared-state
  • Example app: https://simple-shared-state.stackblitz.io/
  • Edit online: https://stackblitz.com/edit/simple-shared-state

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

Keywords

shared state

FAQs

Package last updated on 31 Jan 2020

Did you know?

Socket

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.

Install

Related posts