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

@kubric/redux-knob

v0.0.6

Published

Redux Knob

Downloads

2

Readme

Redux Middleware Toolbelt

Build Status

Maintained by Kubric

Table of contents

Install

yarn add @kubric/redux-knob

Typescript types will be also available soon.

Usage

import { createStore, combineReducers, applyMiddleware } from "redux";
import { ActionQueue, enableBatching, ENABLE_ACTION_QUEUE, FLUSH_ACTION_QUEUE } from "@kubric/redux-knob";

// ActionQueue with default options
const actionQueue = new ActionQueue();
store = createStore(
	enableBatching(
		combineReducers({
			data
		})
	),
	applyMiddleware(...[actionQueue.getWare()])
);
store.dispatch({ type: ENABLE_ACTION_QUEUE });
store.dispatch(actions[0]);
store.dispatch(actions[1]);
store.dispatch({
	type: FLUSH_ACTION_QUEUE,
	payload: actions
});

Recipes

We will be taking help of the following reducer across the recipes.

const data = (state = defaultState, action) => {
	switch (action.type) {
		case "reset":
			return defaultState;
		case "🧀":
			return {
				...state,
				cheese: state.cheese + 1
			};
		case "🍕":
			return {
				...state,
				pizza: state.pizza + 1
			};
		case "🥦":
			return {
				...state,
				broccoli: state.broccoli + 1
			};
		case "🥬":
			return {
				...state,
				leafygreens: state.leafygreens + 1
			};
		default:
			return state;
	}
};

1. Batched Action

import { createStore, combineReducers, applyMiddleware } from "redux";
import { enableBatching } from "@kubric/redux-knob";
store = createStore(
	enableBatching(
		combineReducers({
			data
		}),
		{
			batchType: "batchedType"
		}
	),
	{}
);

const actions = [{ type: "🥦" }, { type: "🥬" }, { type: "🥦" }, { type: "🥦" }];

store.dispatch({
	type: "batchedType",
	payload: actions
});

console.log(store.getState());
// { data: { broccoli: 3, leafygreens: 1, pizza: 0, cheese: 0 } }

2. ActionQueue (With Enable Flush Actions)

import { createStore, combineReducers, applyMiddleware } from "redux";
import { ActionQueue, enableBatching } from "@kubric/redux-knob";

const actionQueue = new ActionQueue({ enableType: "👍", flushType: "👎" });

store = createStore(
	enableBatching(
		combineReducers({
			data // The reducer
		}),
		{
			batchType: BATCH_TYPE
		}
	),
	applyMiddleware(...[actionQueue.getWare()])
);

store.dispatch({ type: "🥦" }); // Follows normal execution
store.dispatch({ type: "👍" }); // Enables the queue, starts queing
store.dispatch({ type: "🥬" }); // Pushes to the queue
store.dispatch({ type: "🥦" }); // Pushes to the queue
store.dispatch({ type: "👎" }); // Flushes the queue, dispatched a batched action
store.dispatch({ type: "🥬" }); // Follows normal execution

3. ThrottleQueue

import { createStore, combineReducers, applyMiddleware } from "redux";
import { ThrottleQueue, enableBatching } from "@kubric/redux-knob";

const throttler = new ThrottleQueue({ filterTypes: [🧀, 🍕], filter: 'include', delay: 1000 });

store = createStore(
	enableBatching(
		combineReducers({
			data // Reducer maintaining counts of food items
		}),
		{
			batchType: BATCH_TYPE
		}
	),
	applyMiddleware(...[throttler.getWare()])
);

store.dispatch({ type: "🧀" }); // This will get queued
store.dispatch({ type: "🧀" }); // This will get queued
store.dispatch({ type: "🥦" });
store.dispatch({ type: "🥦" });
store.dispatch({ type: "🥬" });
store.dispatch({ type: "🍕" }); // This will get queued
store.dispatch({ type: "🥬" });
console.log(store.getState());
// { data: { broccoli: 2, leafygreens: 2, pizza: 0, cheese: 0 } }

// ⏰ After 1000ms the first two actions will be batched & dispatched
console.log(store.getState());
// { data: { broccoli: 2, leafygreens: 2, pizza: 1, cheese: 2 } }