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-saga-kit

v1.2.269

Published

A kit with tools to help create sagas

Downloads

462

Readme

redux-saga-kit

redux-saga is a very sophisticated and awesome library, but it's not that easy to work with.

This package aims to help with the creation and development of sagas.

Getting started

Prerequisites:

Install

npm install --save redux-saga-kit

What This Project Includes

At the moment, this project includes only two methods:

  • sagaCreator - used for creating sagas
  • stateSelector - A helper method to easily create saga selectors

sagaCreator

sagaCreator(definition)

definition: object

returns: Generator Function

The sagaCreator accepts a definitions object, and returns one saga that takes different (using takeEvery or takeLatest) actions, and forks their handlers.

How to use

import { sagaCreator } from 'redux-saga-kit';
  
const saga = sagaCreator({...definitionsObject});

The definition object should have this form:

{actionName: object|func}
 

This will define a handler for the action with the given actionName.
If a function is give, this will be the handler that will be called each time the action is dispatched.

Alternatively, a definition object can be passed. It looks like this:

{
    handler: func,
    takeLatest: bool,
    throttle: bool|number,
    noParams: bool
 }
  
handler (function)

default: no default - must be provided

The handler function to be called every time the action is dispatched.
By default, the handler should be a function, accepting saga params, and that returns a function (or generator function) which will actually handle the action.
The returned function receives {payload} as an argument.

Example:

const myHandler = ({Param1, Param2, ...}) => function* ({payload}) {
  // saga logic here
};

Saga params are used in order to easily test the sagas. You can see more here: redux-saga-tester.

If you choose to work without saga params, you can use the noParams (explained below), and then you can just pass the generator function itself, as so:

const myHandler = function* ({payload}) {
  // saga logic here
};  
  
// or  
  
function* anotherHandler ({payload}) {
  // saga logic here     
}
takeLatest (boolean)

default: false

If this is true, each action cancels previous unfinished handlers. Else, it will call the handler for each action, regardless if previous handlers have finished running.

For more information see: takeLatest

takeFirst (boolean)

default: false

When true, the handler will be called only once, and not at each action "fired".

throttle (boolean | number)

default: 100 (ms)

You can throttle the handlers for the actions by adding the throttle prop.
If throttle value is true then action will be throttled by 100ms.
Alternatively, you can pass a number as the ms value to be throttled by.

For more information see: throttle

cancelOn (string | array[string])

default: null

With this property you can pass an action type, or a list of action types, that when they are "fired", this saga will be cancelled, if it is currently running.

For more information see: cancel

noParams (boolean)

default: false

As described above, this option gives an option to pass a handler without saga params

stateSelector

stateSelector(pathToProp, [defaultValue])

pathToProp: string
defaultValue: any (optional)

returns: Any

How to use

import { stateSelector } from 'redux-saga-kit';
  
const myPropSelector = stateSelector('path.to[my].prop', 'someDefaultValue');

This is a pretty straight forward method.
It uses lodash's get method to get the property from the state.

The first argument is a string representing the path to the property, and the second argument is a default value, if the property is not found, or does not exist.

In addition, you may use additional arguments, that are sent to the select function, by referencing them using ${args[index]}, where index is the index of the argument in the function argument list - 1 (accounting for the selector function being the first argument).

For instance:

import { select } from 'redux-saga/effects';
import { stateSelector } from 'redux-saga-kit';

/*
    Assuming the state has the following structure:
    state = {
        arrayProp: [
            {fooProp: 'foo'}, 
            {fooProp: 'bar'}
        ]
    }
    the function below will log: bar   
*/

function* example() {
    const propIndex = 1;
    const myPropSelector = stateSelector('arrayProp[${args[0]}].fooProp', 'someDefaultValue');
    const value = yield select(myPropSelector, propIndex);
    console.log(value);
}