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

remaster

v1.0.1

Published

Redux generator

Downloads

88

Readme

Remaster - Redux generator

API

remaster({ name, initialState, actions, createDefault }):

name: Name of your reducer.

initialState: Initial state.

actions: Custom actions. By default, remaster will create an type/action for each field inside initialState. If you have a field called rimColor inside your car reducer, you will get car/SET_RIM_COLOR type.

createDefault: Flag for creating the generic type/action described in actions. The default value is true.

setField(reducerName, fieldName, newValue): Update a single value inside one reducer. Useful for updates where you only modify one prop

reducerName: The name you defined in remaster()

fieldName: Some field from your reducer's initial state, defined in remaster()

newValue: field's new value. If this value is not declared, field will return to it's initial value

reset(reducerName): Reset the selected reducer.

reducerName: The name you defined in remaster()

Usage

Example with ReactJS

Install it:

  yarn add remaster
  // or
  npm install --save remaster

Write your reducer's initial state

// ./redux/reducers/user.js

import remaster from "remaster";

const config = {
  name: "user",
  initialState: {
    age: 50,
    name: "John",
    favoriteFruit: "Mango"
  },
  actions: {
    setNameAndAge: (state, { name }) => ({ ...state, name, age: 123 })
  }
};

const user = remaster(config);

// using this, you can see what are your reducer action types
export const UserTypes = user.TYPES;

export default user.REDUCER;

Combine them

// ./redux/reducers/index.js

import { combineReducers } from "redux";
import userReducer from "./userReducer";

export default combineReducers({
  user: userReducer
});

Create your store

// ./redux/store.js

import reducers from './reducers'
import { createStore } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly'

const store = createStore(reducers, composeWithDevTools())

export default store

Wrap your app, just like regular redux

import App from './App'
import React from 'react'
import ReactDOM from 'react-dom'
import Store from '../src/redux/store'
import { Provider } from 'react-redux'

ReactDOM.render(
  <Provider store={Store}>
    <App />
  </Provider>
  , document.getElementById('root'))

Connect your component

import React from 'react';
import { connect } from 'react-redux';

class MyComponent extends React.Component {
  render () {
    const { user } = this.props

    return (
      <div>
        <h3>User</h3>
        <p>Name: {user.name}</p>
      </div>
    )
  }
}

const mapStateToProps = ({ user }) => ({ user })

export default connect(mapStateToProps, null)(MyComponent)

To create a new action, use mapDispatchToProps

import { UserTypes } from "./userReducer";

const mapDispatchToProps = dispatch => {
  return {
    setNameAndAge: payload =>
      dispatch({ type: UserTypes.SET_NAME_AND_AGE, payload })
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(MyComponent);

To update a single field or reset a reducer, import the methods from remaster

import { setField, reset } from "remaster";

export default connect(mapStateToProps, { setField, reset })(MyComponent);