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-relay

v2.0.7

Published

Small library to add relay functionality to redux-saga for more concise sagas 🐎

Downloads

6

Readme

redux-saga-relay

Transform verbose logic in redux-saga into compact callbacks. You need to have redux-saga installed to use the library.

Before

import { takeEvery, all, put } from "redux-saga";
import { BUTTON_PRESSED, FETCH_TODOS, FETCH_USERS, FETCH_PAYMENTS } from "./types";

export function* root() {
  yield takeEvery(BUTTON_PRESSED, _dispatchMultipleRequests),
}

function* _dispatchMultipleRequests(){
    yield all([
      put({ type: FETCH_TODOS }),
      put({ type: FETCH_USERS }),
      put({ type: FETCH_PAYMENTS }),
    ]);
}

After

import { takeEvery } from "redux-saga";
import { relay } from "redux-saga-relay";
import { BUTTON_PRESSED, FETCH_TODOS, FETCH_USERS, FETCH_PAYMENTS } from "./types";

export function* root() {
  yield takeEvery(BUTTON_PRESSED, (action) => 
    relay([FETCH_TODOS, FETCH_USERS, FETCH_PAYMENTS], action)
  )
}

See below for all options and complex transformations.

Install

NPM:

 npm install redux-saga-relay

Yarn:

yarn add redux-saga-relay

Usage

Pass a string and relay a single action:

(action) => relay(TYPE_1, action)

Pass an array of strings and relay multiple actions:

(action) => relay([TYPE_1, TYPE_2, TYPE_2], action)

The triggered action will be spread into TYPE_1, TYPE_2 and TYPE_3 and dispatched to the redux store, after a transformation has been applied (more on transformations below).

Pass a function and relay to a callback:

takeEvery(CUSTOM_BUTTON_PRESS, action => 
  relay(() => {
    // Do something here
  })
)

Extend

You can extend your actions in your sagas with additional payload or metadata using the extend method exposed by the library.

import { relay, extend } from "redux-saga-relay";

takeEvery(CUSTOM_BUTTON_PRESS, action =>
  relay(FETCH_ORDERS, extend(action, { ...payload }, { ...meta }))
)

Catch Issues

The relay code is wrapped in a try - catch block, meaning that you can catch errors in your callbacks, to hook into the catch statement pass a function as the third parameter of the relay function.

(action) => relay(() => {
   const { value } = object.that.does.not.exist; //Bad code
}, null, _recordErrorInSentry)

Transformations

Actions are transformed by default to remove meta.analytics from the action before it is relayed. You can optionally overwrite this transformation by passing a function to the forth parameter of the relay function.

(action) => relay(TYPE_1, action, _recordErrorInSentry, _customTransform)

function _customTransform(action) {
   return _.omit(action, "payload") // apply custom transform to action before it is relayed
}

Authors

License

This project is licensed under the MIT Licence