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

reackt

v0.5.1

Published

A state container built on top of redux and immer that handles both sync or async tasks.

Downloads

14

Readme

Reackt Actions Status

Reackt is a tiny state container built on top of redux and immer.

It helps you build your application without worrying about all the boilerplate codes on defining action types or action creators like when using redux. You only have to define your state and how to update it and leave other thing to reackt.

Reackt is built on top of redux, you have all the benefits with redux like time-travel debugging, easy to implement undo/redo, state persistence, etc.

But unlike redux's pure and synchronous reducer, you can do whatever you want in reackt's update functions, async or sync! You no longer need other middlewares such as redux-thunk, redux-saga or redux-observable to handle all the asynchronous tasks for you.

Reackt makes writing GUI back to the simplest model:

  1. User interaction triggers some kind of event.
  2. Event triggers a function call to compute and update the app state.
  3. The state changes trigger UI re-render so users can have feedback to respond their interaction.

You shouldn't have to consider all those concepts like reducers, actions, action types, action creators in your brain now, reackt just handles it internally for you!

Reackt also has built-in immer support, you can just update your state in a mutable way but have all the benefits of immutable state!

Getting Started

Install

npm install reackt redux immer

or

yarn add reackt redux immer

Usage

reackt only provides one simple API: createStore.

It has pretty much the same signature like redux's createStore except its first argument is an object describing your modular models and other options like below.

function createStore(
  { models, onError = noop, useImmer = true },
  preloadState,
  enhancers
): Store {
  //...
}

Let's try a counter example, we only have to define our state and how to update it, no more action, action types or action creators to worry about!

store.js

import createStore from 'reackt';

const counter = {
  state: 0,
  updates: setState => ({
    increment: () =>
      setState(state => {
        state = state + 1; // setState is like immer's produce, you can just mutate your state here
      }),
  }),
};

export const store = createStore({
  models: { counter },
});

// it returns a redux store with extra enhancement,
// now you can just call your update functions thru dispatch
store.getState(); // -> { counter: 0 }
store.dispatch.counter.increment();
store.getState(); // -> { counter: 1 }

Your update function can also handle async task like this:

const counter = {
  state: 0,
  updates: setState => {
    const increment = () =>
      setState(state => {
        state = state + 1;
      });
    const incrementAsync = async () => {
      await delay();
      increment();
    };

    return {
      increment,
      incrementAsync,
    };
  },
};

// now you can use it just like normal async function
await store.dispatch.counter.incrementAsync();
store.getState(); // -> returns { counter: 1 } after delay

Since we build on top of redux and redux is view-layer agnostic, we can use any other UI library.

For react, we can use react-redux to connect the state to our view components. Using hooks API to make it even more enjoyable.

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider, useSelector, useDispatch } from 'react-redux';

import { store } from './store';

function App() {
  const count = useSelector(state => state.counter);
  const {
    counter: { increment, incrementAsync },
  } = useDispatch();

  return (
    <div>
      <h1>{count}</h1>
      <button onClick={increment}>increment</button>
      <button onClick={incrementAsync}>increment async</button>
    </div>
  );
}

ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById('app')
);

You can check the full counter example on codesandbox.

There is also an advanced github search example here!