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

samsio

v2.0.0

Published

A super simple no frills state management library

Downloads

25

Readme

Samsio

Super simple state management stuff

Samsio is a tiny library that I started to use all over the place. Flux, redux, alt, mobx all kind of went way too far to the point of overcomplicating things that seems like they should be simple and easy to learn. This library doesn't have any frills, and very well may not serve your purpose but it seems to do the job for most small to medium sized React SPAs without much issue.

Here's how to do some stuff.

Stores

import Store from 'samsio/Store';

const UserStore = new Store();
UserStore.updateState({
    users: [
        {
            username: 'test',
            email: '[email protected]',
        }
    ],
    newUserDialogue: false,
});

export default UserStore;

That's it. You can use the updateState function anywhere in your codebase, but the first one here just sets up your default state for this store.

React Container

So, you need to get your state somewhere useful. Use the container, it'll update all the child components with props of the chosen store's state.

import React from 'react';
import Container from 'samsio/Container';
import UserStore from './UserStore';

class UserDisplay extends React.Component {
    render() {
        return <Container store={UserStore}><UserList /></Container>
    }
}

class UserList extends React.Component {
    render() {
        return <ul>
            {this.props.users.map(v => (<li>v.username</li>))}
        </ul>;
    }
}

Inline state updates

A lot of state updates are really simple, changing a value to true, setting a number to +1. There's really no need for these to be actions unless you listen to buzzwords a lot.

import React from 'react';
import UserStore from './UserStore';

class NewUserButton extends React.Component {
    render() {
        return <div onClick={this.newUser.bind(this)}>New User</div>;
    }

    newUser(e) {
        UserStore.updateState({newUserDialogue: true});
    }
}

Actions

However, some actions are inherently more complex, they need reusable, complex logic. But we already have a syntax for reusable pieces of logic, they're called functions.

import UserStore from './UserStore';

function AddNewUser(user) {
    UserStore.updateState({
        users: UserStore.getState().users.concat([user])
    });
}

export {AddNewUser};

React is a great library, and it's conventions and architectures have become ubiquitous for good reason. The state management area however is complex, overcrowded and nonsensical. I've tried many solutions and none of them seem to merge the usecase for large scale, elegant implementation and short boilerplate with easy-to-start interface and a smooth learning curve.

I've created this for myself to use in the interim until something becomes more standard, it simply cannot do many of the things that the alternatives systems can, but they all seem to do those things at the expense of the developer when it's not going to be useful 95% of the time.