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

rapidux

v1.1.0

Published

Swiss army knife for redux and json api development

Downloads

512

Readme

r{api}dux

npm version codecov CircleCI

R{api}dux is a Swiss army knife for dealing with JSON-API in redux

Data reducer example

Api methods

Entity handlers

createLoadHandler(resourceType: string, options: object): nextState

Use it for handle success data loading

Options:

const options = {
  mapToKey: bool|string,  // default: false, map result to custom reducer key
  withLoading: bool,      // default: true, enable/disable loading params
  singular: bool,         // default: false, get first value and store it
  withReplace: bool,      // default: false, replace current values instead of merge it
  addToState: object,     // default: {}, additional props passed to state
}
Simple example

Initial state looks like:

state = {
  posts: {
    isLoaded: false,
    isLoading: false,
    posts: {}
  }
}
const handlers = {
  [LOAD_POSTS.SUCCESS]: createLoadHandler('posts')
}

Resulted state looks like:

state = {
  posts: {
    isLoaded: true,
    isLoading: false,
    posts: [1]
  }
}
Custom example

Initial state looks like:

state = {
  posts: {
    isLoadedPostIds: false,
    isLoadingPostIds: false,
    post: null,
  }
}

Handler:

const handlers = {
  [LOAD_POSTS.SUCCESS]: createLoadHandler('posts', { mapToKey: 'post', singular: true })
}

Resulted state looks like:

state = {
  posts: {
    isLoadedPostIds: true,
    isLoadingPostIds: false,
    postIds: 1,
  }
}

createDeleteHandler(stateKey: string, options: object): nextState

Use it for handle delete data.

Action payload should have deletedId param with singular ID, or deletedIds with array of IDS

Simple example

Initial state looks like:

state = {
  posts: {
    posts: [1, 2]
  }
}

Handler:

const handlers = {
  [DELETE_POST.SUCCESS]: createDeleteHandler('posts')
}
// action.payload.deletedId = 1

Resulted state looks like:

state = {
  posts: {
    posts: [2]
  }
}
Custom key example

Initial state looks like:

state = {
  posts: {
    postIds: [1, 2]
  }
}
const handlers = {
  [DELETE_POST.SUCCESS]: createDeleteHandler('postIds')
}
// action.payload.deletedId = 2

Resulted state looks like:

state = {
  posts: {
    postIds: [1]
  }
}
Multiple IDs

Initial state looks like:

state = {
  posts: {
    postIds: [3, 1, 2]
  }
}
const handlers = {
  [DELETE_POST.SUCCESS]: createDeleteHandler('postIds', {
    addToState: {
      isDeleted: true
    }
  })
}
// action.payload.deletedIds = [2, 1]

Resulted state looks like:

state = {
  posts: {
    postIds: [3],
    isDeleted: true
  }
}

Relationships handlers

createRelationAddHandler(type: string, relationName: string): nextState

Use it for add relation to data reducer. Inject it to data.<type> reducer

Example

Initial state looks like:

state = {
  data: {
    posts: {
      1: {
        id: 1,
        relationships: {
          comments: {
            data: [
              {
                id: 1,
                type: 'comments',
              },
            ],
          },
        },
      },
    },
  }
}

Action looks like:

action = {
  type: CREATE_COMMENT.SUCCESS,
  payload: {
    data: {
      comments: {
        3: {
          id: 3,
          relationships: {
            post: {
              data: {
                id: 1,
                type: 'posts',
              },
            },
          },
        },
      },
    },
  },
}

Handler:

const handlers = {
  [CREATE_COMMENT.SUCCESS]: createRelationAddHandler('comments', 'post')
}

Resulted state looks like:

state = {
  data: {
    posts: {
      1: {
        id: 1,
        relationships: {
          comments: {
            data: [
              {
                id: 1,
                type: 'comments',
              },
              {
                id: 3,
                type: 'comments',
              },
            ],
          },
        },
      },
    },
  }
}

createRelationDeleteHandler(relationsName: string): nextState

Use it for delete relation from data reducer. Inject it to data.<type> reducer

Example

Initial state looks like:

state = {
  data: {
    posts: {
      1: {
        id: 1,
        relationships: {
          comments: {
            data: [
              {
                id: 1,
                type: 'comments',
              },
              {
                id: 3,
                type: 'comments',
              },
            ],
          },
        },
      },
    },
  }
}

Action looks like:

action = {
  type: DELETE_COMMENT.SUCCESS,
  payload: {
    deletedId: 3,
    relationId: 1,
  },
}

Handler:

const handlers = {
  [DELETE_COMMENT.SUCCESS]: createRelationDeleteHandler('comments')
}

Resulted state looks like:

state = {
  data: {
    posts: {
      1: {
        id: 1,
        relationships: {
          comments: {
            data: [
              {
                id: 1,
                type: 'comments',
              },
            ],
          },
        },
      },
    },
  }
}

Entities helpers

denormalize

getEntities

createFields

createReducerHandlers

Need to add docs & tests