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

redux-ramda

v1.0.1

Published

Ramda based functional helpers for Redux

Downloads

846

Readme

redux-ramda

Build Status

Ramda based functional helpers for redux

I like using the cond function from Ramda to describe a list of functions that can occur based on an array of predicates.

Redux reducers feel like they could have a similar API - so I made this wrapper.

Example

import {createReducer} from "redux-ramda"
import {assoc, evolve, append} from "ramda"

// ACTION TYPES
const SET_FILTER = "SET_FILTER"
const ADD_TODO = "ADD_TODO"

// ACTION CREATORS
export const setFilter = (filter) => {
  return {type: SET_FILTER, payload: filter}
}
export const addTodo = (todo) => {
  return {type: ADD_TODO, payload: todo}
}

// REDUCER
const initialState = { filter: null, todos: [] }
export const reducer = createReducer(initialState, [
  [SET_FILTER, assoc("filter")],
  [ADD_TODO, (todo) => evolve({todos: append(todo)})],
])

API

createReducer(initialState, reducerSpec) => reducer

The reducer spec is a list of [predicate, transform] pairs - similar to cond: http://ramdajs.com/docs/#cond

Please see the tests for more examples.

There is some added sugar around the spec:

  • If the predicate isn't a function it will be wrapped in propEq("type"), this allows action types to be passed in directly
  • Transform functions are curried and receive the action payload, followed by the current state. They need to return the next state
  • A pass through condition is added automatically
  • Multiple transform functions can be added to a single predicate - useful for re-using transforms, e.g. a RESET action may have the same effect as a RESET_FILTER and RESET_SORT actions combined. With named functions this becomes nice and declarative. For example:
createReducer(null, [
 [RESET_SORT, resetSortProp],
 [RESET_FILTER, resetFilterProp],
 [RESET, [resetSortProp, resetFilterProp]]
])