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

ramduck-react-redux

v1.0.0

Published

A duck toolbox for react redux based on ramda :-*

Downloads

3

Readme

Ramduck React Redux

Tired of creating containers, of mapping your state to some props. Looking for a more meaningfull approach ?

This little project brings the power ramduck redux to react redux

Previously

// src/components/TodoList.js
import React from 'react'
import { changeTodo, addTodo, toggleTodo, removeTodo } from '../some/reducer/todo'
import { connect } from 'react-redux'

const TodoList = ({
  list = [],
  newTodo = '',
  changeTodo,
  addTodo,
  toggleTodo,
  removeTodo,
}) =>
  <div className="todo list">
    {list.map(todo =>
      <div
        key={todo.id}
        className="todo ${todo.checked ? 'checked' : ''}"
        onClick={toggleTodo(todo.id)}
      >
        <p>{todo.text}</p>
        <i className="ico close" onClick={removeTodo(todo.id)} />
      </div>
    )}
    <input type="text" onChange={changeTodo} value={newTodo} />
    <button onClick={addTodo(newTodo)}>Add todo</button>
  </div>

export default connect(
  state => state.todos,
  dispatch => ({
    changeTodo: event => dispatch(changeTodo(event.target.value)),
    addTodo: text => event => dispatch(addTodo(text)),
    toggleTodo: id => event => dispatch(toggleTodo(id)),
    removeTodo: id => event => dispatch(removeTodo(id)),
  })
)

With ramduck-react-redux (assuming that you are using ramduck redux)

import { map } from 'ramda'
import TodoList, { addTodo, removeTodo, toggleTodo, changeTodo } from '../some/reducer/todos'
import React from 'react'
import { useData, useAction, useActionEff } from 'ramduck-react-redux'

export default () =>
  <div className="todo list">
    {map(todo =>
      <div
        key={todo.id}
        className="todo ${todo.checked ? 'checked' : ''}"
        onClick={useAction(toggleTodo(todo.id))}
      >
        <p>{todo.text}</p>
        <i className="ico close" onClick={useAction(removeTodo(todo.id))} />
      </div>
    ) (useData(TodoList, 'list'))}
    <input
      type="text"
      onChange={useActionEff(event => changeTodo(event.target.value))} 
      value={newTodo}
    />
    <button onClick={useAction(addTodo(useData(TodoList, 'newTodo')))}>Add todo</button>
  </div>

Installation

with npm: npm i ramduck-react-redux --save

with yarn: yarn add ramduck-react-redux

Api

This module is using React 16.8 hooks, you must have a version compatible before using this library.

useData :: (String, String) -> a

Use a given dot path for a given state name

import { useData } from 'ramduck-react-redux'

useData('myRootReducer', 'a.b.c') // will invoke store.getState().myRootReducer.a.b.c

If you are using ramduck redux createReducer function it will automatically add a toString method over your reducer allowing you to use your reducer directly inside useData:

import { createReducer, init } from 'ramduck-redux'
import { useData } from 'ramduck-react-redux'

const reducer = createReducer('user', [
  init({ id: '', username: 'anonymous' })
])


useData(reducer, 'username') // 'anonymous'

useState :: (String, (a -> b)) -> b

import { useState } from 'ramduck-react-redux'

useState('myRootReducer', state => state.a.b);
// will invoke store.getState().myRootReducer.a.b

useDataOr :: (a, String, String) -> a

import { useDataOr } from 'ramduck-react-redux'

useDataOr('No friend', 'user', 'friends.0.username')
// 'No friend' if store.getState().user.friends[0].username is not set

useAction :: Action | (* -> Action) | Functor (Action | (* -> Action)) -> React.SyntheticEvent -> *

Perform a dispatch effect of the given action:

<button onClick={useAction(changeUsername(newUsermane))}>Change username</button>

// It also support action creator with no arguments:
<button onClick={useAction(submit)}>Submit</button>


// You can pass any functor to the function:
<button onClick={useAction([
  submit,
  [ toggleTodo(id), Maybe.just(addTodo(id)) ]
])}>Do more stuff</button>

useActionEff :: (React.SyntheticEvent -> Action | (* -> Action) | Functor (Action | (* -> Action)) -> React.SyntheticEvent -> *

Allow the usage of the synthetic event when creating actions

import { safe, isString } from 'crocks'


<input type="text" onChange={useActionEff(event =>
  changeTodo(event.currentTarget.value)
)} />

// This will perform an add todo only if the target value is
// a valid String (thanks to the `Maybe` functor from crocks).
<input type="text" onChange={useActionEff(event =>
  event.target.value
  |> safe(isString)
  |> map(addTodo)
)}>Add todo</button>