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

redux-simplux

v1.0.4

Published

redux-simplux is a simple state container with no indirection, no magic. It is built on [Redux](https://github.com/reactjs/redux) so you can reuse all the middlewares / all the tools you are used to.

Downloads

12

Readme

Simplux (aka redux-simplux)

Simplux is a simple state container with no indirection, no magic. It is built on Redux so you can reuse all the middlewares / all the tools you are used to.

simplux

Before proceeding further, you should read this article to understand what this lib is solving.

Usage

(You need redux if you don't have because it's a peer dependency : npm install --save redux)

npm install --save redux-simplux

To understand, nothing better than a classical example : the counter

import { createStore } from 'redux-simplux';

const initialState = { counter: 0 };
const store = createStore(initialState);

function increment() {
  const current = store.getState().counter;
  store.setState({counter: current + 1});
}
function decrement() {
  const current = store.getState().counter;
  // you can choose the name of the final action dispatched by redux
  store.setState({counter: current - 1}, 'DECREMENT');
}

// ...

increment(); // { counter: 1 }
increment(); // { counter: 2 }
decrement(); // { counter: 1 }

To use with React, you need to add npm install --save react-redux

import {increment, decrement} from './actions'; // functions described above
import store from './store'; // store created by createStore
import {Provider, connect} from 'react-redux';

// CounterDumb is just a dumb stateless generic counter for rendering
const CounterDumb = (props) => (
  <div>
    <button onClick={props.onClickMinus}> - </button>
    {props.value}
    <button onClick={props.onClickPlus}> + </button>
  </div>
);

// CounterControlled is stateless too but knows the controller, it knows "increment" & "decrement".
// (NB : you can also map this in mapDispatchToProps arg of the connect function)
const CounterControlled = (props) => (
  <CounterDumb
    value={props.value}
    onClickMinus={decrement}
    onClickPlus={increment}
    />
);

/*
* Don't do over-engineering. You don't need to separate CounterDumb and CounterControlled if
* it is not necessary, it is just an example.
*  const Counter = (props) => (
*   <div>
*     <button onClick={decrement}> - </button>
*     {props.value}
*     <button onClick={increment}> + </button>
*   </div>
* ); is fine too !!
*
*/

const CounterContainer = connect(
  (state) => ({value: state.counter}), // mapsStateToProps
)(CounterControlled);

render(
  <Provider store={store.reduxStore}>
    <CounterContainer />
  </Provider>,
  document.getElementById('root')
);

Api

  • createStore(initialState: State, reduxEnhancer = undefined): Store<State>

Create the store and return it. The first parameter is mandatory and needs to be a plain Object. The second parameter is optional and is used when creating the redux internal store, please refer to the redux documentation if you want more information.

  • getState(): State

Retrieve the current state

  • setState(newState: $Shape<State>, reduxAction: string | Object = 'SET_STATE'): void

Set the new current state. To mimic the React.setState behavior, the newState parameter could be an object containing only the keys to update (but it's juste a simple merge). For example :

// suppose your current state is {x: 1, y: 2}

setState({x: 3}); // your state is now {x: 3, y: 2}

Note : The new state is a new Object (new reference) so you can use the lib with immutability pattern.

The second parameter reduxAction is optional. You can specify the redux action that will be dispatched by the redux internal store. This can be useful if you have defined or want to define specifics behaviors with enhancers (middlewares) or for your tools (Redux Devtools, logging, ..). You can give a string or a plain Object.

  • reduxStore

The internal redux store