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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@churchcommunitybuilder/redux-modules

v0.2.1

Published

This library is designed to reduce the boilerplate of interacting with an api, normalizing and caching responses, and describing api states.

Readme

Redux Modules

This library is designed to reduce the boilerplate of interacting with an api, normalizing and caching responses, and describing api states.

Installation

yarn add @churchcommunitybuilder/redux-modules

Usage

There are 3 main assumptions of this library

  1. You are using React
  2. You are using Redux
  3. You are using Redux Thunk with an extra argument that interacts with an api

You'll first need to make sure that your root reducers composes the two reducers exported from this library.

import { moduleReducers } from '@churchcommunitybuilder/redux-modules'

const appReducer = combineReducers({
  ...moduleReducers,
  ...otherAppReducers
})

Next, make a moduleFactory that encapsulates how to pass requests to your thunk api arg.

import { getModuleFactory } from '@churchcommunitybuilder/redux-modules'

export const moduleFactory = getModuleFactory((request, api) =>
  api(request),
)

where api is you thunk arg and request is defined as

interface RequestConfig {
  url: string
  method?: 'get' | 'post' | 'put' | 'delete'
  params?: {}
  data?: {}
  headers?: {}
}

At this point, everything should be wired up and you can begin creating modules.

inteface Entity {
  id: number
}

const module = moduleFactory.create<Entity>()(
  moduleFactory.createSchema('moduleName'),
  {
    get: moduleFactory.get<Entity>(({ id }) => ({
      url: `some_endpoint/${id}`,
    })),
    getList: moduleFactory.getList<Entity>(({ id }) => ({
      url: `some_endpoint/${id}`,
    })),
    put: moduleFactory.put<Entity>(({ id }) => ({
      url: `some_endpoint/${id}`,
    })),
    post: moduleFactory.post<Entity>(({ id }) => ({
      url: `some_endpoint/${id}`,
    })),
    delete: moduleFactory.delete<Entity>(({ id }) => ({
      url: `some_endpoint/${id}`,
    })),
  },
)

Api

create

This is used to create the module and pull together the normalizr schema and the api definitions. Returns the schema, entity selectors, and the api definitions

createSchema

A thin wrapper around creating a normalizr schema

apiDefinitions

All api definition factories share a similar signature:

  1. A function taking the api params and returning a request config object.
  2. An optional unique identifier for the module (since the url/http method is by default the unique id)

Each api definition has the following values:

  • api: The api action creator that was passed in
  • execute: A thunk that sets pending statuses, calls the api, and merges the response into redux state
  • metaSelector: A selector to get the metadata about the module (i.e. current api status, item ids, paging)
  • getKey: A helper to get the module's unique key

get

This api definition has all of the above, with the addition of a useModule hook that returns the entity and metadata for a module

getList

This api definition also has useModule, and additionally has an itemsSelector which will get the entities for the module

Testing

This library exports two test helpers from @churchcommunitybuilder/redux-modules/testing.

getModuleMock

This can be used to mock modules and entities in your redux store. actions is an array that should be dispatched to your store

import { getModuleMock } from '@churchcommunitybuilder/redux-modules/testing'

export const moduleMock = getModuleMock<Entity>(
  module.schema,
  defaultEntity,
)

const entity = moduleMockEntities(1)
const entities = moduleMockEntities(10)
const entity = moduleMockEntities({ id: 1 })
const entities = moduleMockEntities([{ id: 1 }, { id: 2 }])

const { entity, actions} = moduleMock.mockModule(1, 'uniqueModuleKey') // creates entity, and updates the module's metadata
const { entity, actions} = moduleMock.mockModule(1) // creates one default module
const { entities, actions} = moduleMock.mockModule(10) // creates ten default module
const { entity, actions} = moduleMock.mockModule({ id: 1 }) // creates one entity merged with the default entity
const { entities, actions} = moduleMock.mockModule([{ id: 1 }, { id: 1 }]) // creates two entity merged with the default entity

mockMeta

Used to mock a modules metadata

const meta = mockMeta({ status: ApiStatus.Pending })