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

oberon-redux

v0.4.0

Published

Update your redux state directly from your components. No reducers, no actions.

Downloads

12

Readme

Oberon Redux

npm Travis

Update your state directly from your components. No reducers, no actions.

Installation

npm i oberon-redux

or

yarn add oberon-redux

The gist

This package is designed to provide an interface to using redux that matches the development thought proces. When using redux, generally you need to define your default state, provide reducers to define how your state can get updated and then create an interface to trigger these updates through action creators. We feel it makes more sense to focus on creating components and use the redux state whenever you need to share state between components or component instances (i.e. through persistence). Doing this should not break your workflow or thought process. Therefor with this package, all you need to do to use your redux store is the following:

  • Define your initial state.
  • Update the state directly from your components.

Updater functions are provided that implement common state update patterns.

API

For an overview of all available updater functions, refer to the full API documentation

Quick usage

Define your default state

// The default state us just a plain object
export default {
    currentIndex: 0,
};

Bind the reducer to your redux store

You can add the reducer as the root reducer when creating your store, but we recommend using combine reducers so you have the option to add other redux related packages, for example to manage your api calls and data.

import { createReducer } from 'oberon-redux';
import defaultState from './defaultState';

const reducer = createReducer(defaultState, 'app');
const rootReducer = combineReducers({app: reducer});
const store = createStore(rootReducer, composeEnhancers(applyMiddleware(thunk)));

Use the state in your components

import React from 'react';
import { connect } from 'react-redux';
import { update } from 'oberon-redux';

// Use react-redux to bind your state and dispatch updates. 

const mapStateToProps = state => ({
    currentIndex: state.app.currentIndex,
});

const mapDispatchToProps = dispatch => ({
    updateIndex: index => dispatch(update('app.currentIndex', index))
});

const enhance = connect(mapStateToProps, mapDispatchToProps);

const MyComponent = props => (
    <div>
        <div>The current index is {props.currentIndex}</div>
        <div>
            {[0, 1, 2, 3].map(index =>
                <button key={index} onClick={() => props.updateIndex(index)}>{index}</button>
            )}
        </div>
    </div>
);

export default enhance(MyComponent);

Using with TypeScript

This package includes TypeScript type definitions. So type checking on all functions should be enabled by default. To add type checking on the path names given to updater functions, you can use the createStatePaths function to retrieve a StatePathTree. This is a recursive structure that you can use instead of strings when passing the state path to an updater function.

import { createStatePaths } from 'oberon-redux';

export const paths = createStatePaths(defaultState, 'app');

// somewhere in your component
dispatch(update(paths.currentIndex, 3));
// is same as
dispatch(update('app.currentIndex', 3)); 
// but with type checking. Catch errors before they happen!