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

houx

v2.0.0

Published

Light React plugin which implements flux architecture using the built-in React API.

Downloads

10

Readme

✨Houx

Light React plugin which implements flux architecture using the built-in React API.
It connects React.Context with useReducer() from React Hooks to provide global state reducers.

Allows you to send asynchronous actions (redux-thunk style).
It has a built-in simple loger witch shows dispatched actions.

:pencil: Prerequisites

:hammer: Installation

Open you fav terminal in project root and type:

npm install --save houx

✍ Example project

https://github.com/glaskawiec/houxTasks

HouxProvider API

| prop | description | example value | | ------------- | ------------- | ------------- | | reducers | Flux reducers | { spaceName: (state,action) => newState } | | logDispatchedActions | Enables simple dispatched actions loging | true |

✌ Usage

Create your actions and reducers:

export const TASKS_ADD = 'TASKS_ADD';
export const TASKS_REMOVE = 'TASKS_REMOVE';
export const TASKS_COMPLETE = 'TASKS_COMPLETE';

export const initialState = {
    tasks: [],
    nextId: 0
}

const tasksReducer = (state = initialState, action) => {
    switch (action.type) {
        case TASKS_ADD:
            const newTodo = {
                ...action.task,
                id: state.nextId
            }
            ++state.nextId;
            return {
                ...state,
                tasks: [...state.tasks, newTodo]
            }
        case TASKS_REMOVE:
            --state.nextId;
            return {
                ...state,
                tasks: state.tasks.filter((task) => task.id !== action.id)
            }
            case TASKS_COMPLETE:
            return {
                ...state,
                tasks: state.tasks.filter((task) => task.id !== action.id)
            }
        default: return state;
    }
}

export default tasksReducer;

Use HouxProvider and pass reducers to enable access to global state from any app component:

import React from 'react';
import ReactDOM from 'react-dom';
import { HouxProvider } from 'houx';
import App from './App';
import discover from './Flux/Reducers/tasks';

const reducers = {
    tasks
};

ReactDOM.render(
  <HouxProvider reducers={reducers} logDispatchedActions>
    <App />
  </HouxProvider>, document.getElementById('root'),
);

Access dispatch and global state using useHoux hook:

import React from 'react';
import { useHoux } from 'houx';
import { removeTask } from '../../../flux/actions/tasksActions';

export default function RemoveButton(props) {
    const { state, dispatch } = useHoux();

    const onClick = () => {
        dispatch(removeTask(props.itemId));
    }

    return (
        <span
            className="cursor-pointer"
            style={{ marginLeft: '0.5em' }}
            onClick={onClick}
            role="img"
            aria-label="cross">❌</span>
    )
}

glaskawiec © 2019 - MIT license