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

redux-kittens

v0.1.2

Published

Redux middleware kit for http requests, websockets, timers etc

Downloads

3

Readme

Redux KITtens 🐾

Redux middleware kit Simple way to create http requests, create and manage websockets, timer, promises etc. - just pass the plain objects objects as a payload. Also every KITten already have the built-in logger, so no need to add some other logging middleware.

Installation

npm install -s redux-kittens

Usage

Global settings

import {
  reduxKittens, /* all in one initialization */

  delayKitten, ... /* or add only kittens you need */
} from 'redux-kittens';

const options = {enableLog: true};

const store = applyMiddleware( ...reduxKittens(options) )(createStore)(reducer); // Apply all the middlewares
   OR
const store = applyMiddleware( /* one by one */
  delayKitten(options),
  timerKitten(options),
  superagentKitten(options),
  socketIoKitten(options),
  storageKitten(options),
  promiseKitten(options)
)(createStore)(reducer);

🐱 Timer kitten

timerKitten(options)

Payload should be a plain object with properties:

  • use: 'timer'
  • method - 'start' or 'stop'
  • id - timer's ID, optional (you can have several timers with the different IDs)
  • interval - interval in ms

Start timer

store.dispatch({ 
  type: 'TIMER_CALL', //or whatever you want
  payload: {
      use: 'timer',
      method: 'start',
      id: 'my_timer_number_one', 
      interval: 1000 //one second      
    }
  });

In the reducer you will get: { meta: { sequence: 'start' }} and then { meta: { sequence: 'tick', iteration: NN /* number of iteration */ }} on every timer's call. If the timer with this name is already started this action call will be ignored.

Stop timer

...
  payload: {
      use: 'timer',
      method: 'stop',
      name: 'my_timer_number_one',
    }

In the reducer you will get: { meta: { sequence: 'stop' }}

Restart timer

...
  payload: {
      use: 'timer',
      method: 'restart',
      name: 'my_timer_number_one',
    }

[options]

  • enableLog - set to true to enable console logging

🐱 Delay kitten

delayKitten(options)

Payload should be a plain object with properties:

  • use: 'delay'
  • delay - interval in ms

Reducer events:

  • { meta: { sequence: 'begin' }} - after right the delay creation
  • { meta: { sequence: 'complete' }} - at the end of the interval

[options]

enableLog - set to true to enable console logging


🐱 Superagent kitten

superagentKitten(options)

Middleware for the async requests via http and https. It uses promisified superagent library.

Payload should be a plain object with properties:

  • use: 'request'
  • url
  • method - 'GET', 'POST' etc.
  • query - request query, as an object
  • data - request payload
  • accept
  • boundary
  • sendAsForm - set to true if you want to send the data as a form
  • contentType
  • files - pass here the FileList object if you want to upload the files, the form will be created automatically, content of the data will be added as a form fields
  • allowedFileTypes - array, MIME file types for upload, or just image or video - all the other files will be ignored
  • reportProgress - set it to true if you want to receive the events about the operation progress, for example during the uploading of the large files

Create request

store.dispatch({ 
  type: 'GET_REMOTE_URL', //or whatever you want
  payload: {
      use: 'request',
      method: 'GET',
      url: 'https://your.site/api'      
    }
  });

Reducer events

  • { meta: { sequence: 'begin' }} - request was made
  • { meta: { sequence: 'complete' }, payload: { ...dataFromServer }} - data recieved
  • { meta: { sequence: 'error' }, payload: { ...ErrorData }} - error during the request

[options]

  • enableLog - set to true to enable console logging
  • getToken - optional function, provide auth token here, getToken: () => yourCustomToken

Authentication

Middleware automatically gets the value of the store session.token (supported both plain JS object and Immutable reducers), it will be send in the 'Authorization' header field. If you want to manually specify the 'Authorization' header value, use the getToken parameter in the options


🐱 Socket.io kitten

socketIoKitten(options)

Middleware for socket.io. It uses socket.io-client library.

Payload should be a plain object with properties:

  • use: 'socketIo'
  • url
  • method - connect or disconnect
  • name - socket name
  • query - query params for connection
  • listeners: [] - array of listeners, 'connect', 'disconnect', custom event names

Connect to server

store.dispatch({ 
  type: 'TIMER_CALL', //or whatever you want
  payload: {
    use: 'socketIo',
    method: 'connect',
    name: 'someSocket',
    url: 'https://your.site/socket_io',
    query: { id: 2 },
    listeners: ['connect', 'disconnect', YOUR_EVENT_NAME, ...]
  }
});

Reducer events

  • { meta: { sequence: 'sequence: 'connectRequest' }} - rigth after the 'connect' action call
  • { meta: { sequence: 'connect' }} - connected to server
  • { meta: { sequence: 'disconnect' }} - disconnected to server
  • { meta: { sequence: YOUR_EVENT_NAME }} - when socket receives YOUR_EVENT_NAME from the server. YOUR_EVENT_NAME should be in the listeners list

[options]

  • enableLog - set to true to enable console logging
  • getToken - optional function, provide auth token here, getToken: () => yourCustomToken
  • socketOptions - look the socket.io-client documentation

Authentication

Middleware automatically gets the value of the store session.token (supported both plain JS object and Immutable reducers), it will be send in the 'Authorization' header field. If you want to manually specify the 'Authorization' header value, use the getToken parameter in the options


🐱 Storage kitten

storageKitten(options)

Middleware for local storage in browser apps and AsyncStorage in ReactNative

Payload should be a plain object with properties:

  • use: 'storage'
  • method - get, set or remove
  • data - key name, or object with keys and values

Reducer events

  • { meta: { sequence: 'begin' }} - rigth after the action call
  • { meta: { sequence: 'complete' }, payload: { ...yourData }} - data fetched
  • { meta: { sequence: 'error' }} - some error occurred

[options]

  • enableLog - set to true to enable console logging

🐱 Promise kitten

promiseKitten(options)

Just pass the Promise as a payload, and it will be handled with this middleware

Reducer events

  • { meta: { sequence: 'begin' }} - rigth after the action call
  • { meta: { sequence: 'complete' }} - if the promise resolved
  • { meta: { sequence: 'error' }} - if the promise was rejected

[options]

  • enableLog - set to true to enable console logging