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

reduxefy

v0.0.1

Published

**Reduxefy** is a bare minimum lightweight implementation of Redux that that won't weigh down your code like a sumo wrestler on a trampoline.

Downloads

1

Readme

Reduxefy

Reduxefy is a bare minimum lightweight implementation of Redux that that won't weigh down your code like a sumo wrestler on a trampoline.

While Redux is a true masterpiece of state management (Dan Abramov is a genius), with an elegant design and a powerful set of features, I wanted to create my own version that mimics its core functionality without ever peeking at the source code. It's like I built this while blindfolded and juggling flaming torches - but don't worry, I promise it works!

Installation

You can install this package via npm by running:

npm install reduxefy

Usage

Reduxefy may be a lightweight implementation of Redux, but it still packs a punch. Just like Redux, it exports:

createStore

combineReducers

applyMiddeware enhancer

thunkMiddleware

to give you all the essential tools for managing your app's state. And with Reduxefy's stripped-down approach, you can enjoy all of these features without feeling like you're carrying around unnecessary baggage. So go ahead, give Reduxefy a spin and see how it compares to the big dog in the yard.

Use createStore just like you'd do with Redux

import { createStore } from 'reduxefy';

function counter(state = 0, action) {
   switch (action.type) {
 	    case 'INCREMENT':
 		      return state + 1;
 	    case 'DECREMENT':
 		      return state - 1;
 	    default:
 		      return state;
   }
}

const store = createStore(counter);

const unsubscribe = store.subscribe(() => console.log(store.getState()));

store.dispatch({ type: 'INCREMENT' });
// 1
store.dispatch({ type: 'INCREMENT' });
// 2
store.dispatch({ type: 'DECREMENT' });
// 1
unsubscribe();

Reduxefy includes the "combineReducers" feature so you can combine multiple reducers into a single one. You can also create a store with any enhancer you want! The "applyMiddleware" enhancer is shipped by default that lets you add any middleware to your store. And to tackle those pesky Async functions, the "thunkMiddleware" is also included that will make your life so much easier. Who needs a magic wand when you've got Reduxefy?"

Here is a more complete example:

import { createStore, combineReducers, applyMiddleware, thunkMiddleware } from "reduxefy";

const userInitialState = {
    users: [],
    loading: false,
    currentUser: ""
};

export const userReducer = (state = userInitialState, action) => {
    switch (action.type) {
        case "ADD_USER":
            return { ...state, users: [...state.users, action.payload] };
        case "TOGGLE_LOADING":
            return { ...state, loading: !state.loading };
        case "SET_USER":
            return { ...state, currentUser: action.payload };
        default:
            return state;
    }
}

const postInitialState = {
    posts: [],
}

export const postReducer = (state = postInitialState, action) => {
    switch (action.type) {
        case "ADD_POST":
            return { ...state, posts: [...state.posts, action.payload] };
        default:
            return state;
    }
}

export const countReducer = (state = 0, action) => {
    switch (action.type) {
        case "ADD_NUM":
            return state + action.payload;
        default:
            return state;
    }
}

const setUser = (id) => {
    return async (dispatch, getState) => {
        dispatch({ type: "TOGGLE_LOADING" });
        const response = await fetch(`https://jsonplaceholder.typicode.com/post/${1}`);
        const data = await response.json();
        dispatch({ type: "TOGGLE_LOADING" });
        dispatch({ type: "SET_USER", payload: { id, name: data.title } });
    }
}

const combinedReducer = combineReducers({
    user: userReducer,
    post: postReducer,
    count: countReducer
});

const store = createStore(combinedReducer, undefined, applyMiddleware(thunkMiddleware));

store.subscribe(() => console.log("From Subcription", store.getState()));

console.log(store.dispatch({ type: "ADD_USER", payload: "John" }));
console.log(store.dispatch({ type: "ADD_USER", payload: "Connor" }));
store.dispatch({ type: "ADD_NUM", payload: 15 });
store.dispatch({ type: "SET_USER", payload: "Jack Sparrow" });
// store.dispatch(setUser(1));
// install fetch to run this

You're free to take a snoop at the source code and witness the magic for yourself. Sure, I might have taken a completely different approach than the Redux overlords and it might not be as elegant, but that's actually the best part about this.

License

MIT