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

redux-jam

v0.1.0-alpha.6

Published

A Redux JSON-API model layer.

Readme

redux-jam

npm version Downloads

redux-jam is a framework for managing the complexity of multiple data sources with different fetching and storage characteristics, while using standard, flexible, and known systems, such as Redux.

Storing data fetched from a server locally is a very attractive method of improving user experience, but it comes with significant difficulties. Deciding when to invalidate a locally cached dataset, and how to combine remote and local data can be a source of immense complexity. This is especially true when building an application designed for offline capabilities.

Installation

npm install redux-jam

or

yarn add redux-jam

Add the JAM model reducer to your root reducer:

import {reducer as model} from 'redux-jam'

const rootReducer = combineReducers({
  model,
  ...
})

export default rootReducer

Defining a Schema

Before data can be manipulated a schema describing the structure of the data must be defined. There are a number of ways to do it, the two most common are to define the data manually, or import it automatically using an external package.

Manual Definition

Schemas are built using the Schema class:

import {Schema} from 'redux-jam'

let schema = new Schema()

To define models in a schema, use the merge method, which accepts an object argument describing a part of a schema:

schema.merge({})

merge may be called any number of times. Each subsequent call will overwrite any overlapping models.

The structure of the schema object is similar in some ways to the structure of a JSON-API object. Take for example the following definition of a movie:

{
  movie: {
    attributes: {
      name: {
        required: true        
      },
      duration: {},
      year: {}
    },
    relationships: {
      actors: {
        type: "person",
        many: true,
        relatedName: "actedIn"
      }
    }
    api: {
      list: () => {},
      detail: () => {},
      create: () => {},
      update: () => {},
      delete: () => {}
    }
  },
  person: {
    attributes: {
      name: {
        required: true
      }
    },
    api: {
      list: () => {},
      detail: () => {},
      create: () => {},
      update: () => {},
      delete: () => {}
    }
  }
}

This defines two models: movie and person. The api sections of each model are placeholders for calls to API endpoints. They should return promises, which in turn return JSON-API structured data.

Options for attributes are currently limited to required.

Options for relationships:

  • type

  • required

  • many

  • relatedName

Django + DRF

If you're using Django and DRF, your schema can be loaded into JAM automatically, which is particularly convenient.

Refer to Django-JAM

Loading Data

Fetching data from the server is achieved with a higher order comonent, withView. Views collect a set of one or more queries and provide the resultant data to a React component.

The following snippet shows a React component that loads movies whose title contains the term "Rocky", and sorts them on year:

import React from 'react'
import {withView} from 'redux-jam'
import schema from 'models'

const view = schema.view({
  name: 'movieList',
  queries: {
    movies: {
      type: 'movie',
      filter: F.contains('title', 'Rocky'),
      sort: 'year'
    }
  }
})

@withView(view)
class MoviesList extends React.Component {
  render() {
    const {moviesList} = this.props
    const {loading, queries} = moviesList
    if (!loading) {
      return (
        <ul>
          {queries.movies.map(m => <li>{m.title}</li>}
        </ul>
      )
    }
    else
      return null
  }
}

Mutating data

redux-jam provides a form like interface for mutating data.

import React from 'react'
import {withForm} from 'redux-jam'
import schema from 'models'

@withForm({type: 'movie'})
class MoviesList extends React.Component {
  render() {
    const {renderField} = this.props
    // TODO
  }
}

Filtering

Transactions