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

kortex

v3.4.0

Published

Dead simple state management for react.

Downloads

7

Readme

kortex

Build Status Coverage Status

Dead simple state management for react.

Installation

$ npm install kortex

Examples

Usage

Initial setup

Before you can start connecting components you will need to create both your actions as well as your state, and create a connector instance using these:

import { Actions, Connector, State } from 'kortex';

const actions = new Actions({
  someAction: () => {},
  someOtherAction: () => {},
});

const state = new State({
  someStateValue: true,
  someOtherStateValue: 'totes',
});

const connector = new Connector(actions, state);

Connecting

Connecting a component to the state should feel familiar, simply call Connector.connect, passing an object mapping your component's interested keys to the expected prop name, like so:

function MyAwesomeComponent({ someAction, someStateValue }) {
  return (
    <span>Hello {someStateValue}</span>
  );
}

const MyAwesomeConnectedComponent = connect(MyAwesomeConnectedComponent, {
  someAction: 'actions.someAction',
  someStateValue: 'state.someStateValue',
});

Now MyAwesomeConnectedComponent will receive all props passed down from the parent, and inject those requested from the state

State

Defining state

The initial state is defined upon creation of the state instance. The object passed during creation of this instance is used as the starting state.

Updating state

The global state can be updated by calling set with the object path and value you would like to set it to:

import { state } from './state';
state.set('foo', 'foo');                    // sets the key 'foo' to the value 'foo'
state.set('bar', {});                       // sets the key 'bar' to an empty object
state.set('bar.foo', 'bar');                // sets the key 'foo' of the object 'bar' to 'bar'
state.set('dar.foo', 'bar');                // does nothing because the key 'dar' does not exist

Actions

Defining actions

Available actions are defined up creation of the actions instance. The object passed during creation is used to define the actions available.

Running actions

You can run actions via the run function, passing the path of the action you want to run, along with any params you want to pass, and a callback if desired:

import { actions } from './state';
actions.call();                             // passes no parameters, nor uses a callback
actions.call('foo', 'foo');                 // passes 'foo' as a parameter, does not use a callback