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

redoodle

v2.10.0-rc1

Published

An addon library for Redux that enhances its integration with TypeScript.

Downloads

4,790

Readme

Redoodle

Redoodle is an addon library for Redux that enhances its integration with TypeScript.

Redoodle includes a few major categories of addons that can be used individually and play well with each other:

Circle CI npm

Motivation

Redux brought sanity to state management, and has found itself a seat in many a React application's architecture. TypeScript is also gaining a large amount of traction, and has impressed the community with its month-over-month high quality releases. Unfortunately, there were a few places where default Redux and TypeScript failed to play well with each other:

  1. Redux Actions have magic string types and opaque payloads, with no obvious mechanism to track the correlation between the two.
  2. Redux Reducers have no easy way to infer correct typings for different Action branches.
  3. The TypeScript/JavaScript STL lacks good immutable state update functions. While this has gotten better with Object and Array spread and their reasonable typings, there is still a dearth of exact behavior for certain common Redux update workflows.

Redoodle attempts to solve these integration pains, and takes a stab at a few more common points of developer frustration when working with Redux and Typescript.

Features

Typed Actions

Typed Actions do the most legwork to bridge the Redux-TypeScript divide, by correlating Action magic type strings with Action magic payloads. With Redoodle, you can create an Action Definition, and then use that Definition in all places you were previously guessing, casting, or crying.

import { defineAction, TypedReducer, setWith } from "redoodle";

// FlipTable is an action Definition for actions of type "FlipTable",
// and associates the given payload type with the action.
const FlipTable = defineAction("FlipTable")<{
  tableId: string;
  face: "happy" | "angry";
}>();

// We can use a Definition to create a matching Action. This is all type-safe.
// At runtime, the `action` below has the value
//
//    {
//      type: "FlipTable",
//      payload: {
//        tableId: "2567f216-59b7-4bfe-b46f-909c6711fea4",
//        face: "happy"
//      }
//    }
//
const action = FlipTable({
  tableId: "2567f216-59b7-4bfe-b46f-909c6711fea4",
  face: "happy"
});

// We can also use Definitions to create Reducers that offer slick type inferencing.
// No more manual casts!
interface BanquetHall {
  [tableId: string]: {
    isFlipped: boolean;
  }
}

// banquetHallReducer is a standard Redux Reducer<BanquetHall>. Nothing fancy.
const banquetHallReducer = TypedReducer.builder<BanquetHall>()
  // FlipTable.TYPE is the plain string "FlipTable", but it's branded with
  // rich compile-time information about its associated payload type `{tableId, face}`.
  .withHandler(FlipTable.TYPE, (state, { tableId, face }) => {
    // All of the operations here are 100% type-safe. If I misspelled `isFlipped` below
    // in either place, or fail to copy the correct subset of state when applying my
    // immutable copies, the compiler will save me!
    return setWith(state, {
      [tableId]: setWith(state[tableId], {
        isFlipped: !state[tableId].isFlipped
      })
    });
  })
  .build();

For more on Typed Actions, probably the most simple and significant utility Redoodle offers, check out the Redoodle docs.

Compound Actions

The only builtin Action Definition that Redoodle ships with is the CompoundAction, which is a simple higher-level Action that wraps another set of Actions. Its alternatives in stock Redux is either to

  1. Create more complex DoFooAndBar actions, which have the drawback of making every Reducer that cares about DoFoo or DoBar also care about DoFooAndBar.
  2. Dispatch DoFoo and DoBar individually, which has the drawback of causing multiple Store subscription events, which often results in e.g. multiple React renders. It also has the drawback of publishing a possibly inconsistent intermediate state when DoFoo was applied but not DoBar.
import { CompoundAction } from "redoodle";

const doFoo: Action = {...};
const doBar: Action = {...};

store.dispatch(CompoundAction([doFoo, doBar]));

To use CompoundActions, your store must be configured to correctly unwrap and reduce them; thankfully Redoodle comes with a compoundActionsEnhancer() (or the simpler reduceCompoundActions decorator) for exactly that.

For more on CompoundActions, check out the Redoodle docs.

Utilities

Redoodle packages a number of utility functions, some explicitly for clean TypeScript immutable state manipulation, some for completeness in developer experience.

On Initial State Management

Redoodle firmly believes that specific benefits the TypeScript compiler provides should change the way we think about Redux State initialization. This shifts the behavior of some Redoodle utilities slightly to be more ergonomic for developers, and is discussed in greater detail here.

Documentation

License

Apache 2.0