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-sagas-async

v1.0.2

Published

An alternative and simplified version of redux-saga using await/async instead of generators.

Downloads

3

Readme

redux-sagas-async

redux-sagas-async is an alternative and simplified version of redux-saga using await/async instead of generators.

Getting started

Install

$ npm install redux-sagas-async

API

  • takeEvery: Add listener for the specific action.
  • dispatch: Redux dispatch function.
  • select: Function to select the data from the store (receives state as argument).
  • delay: Promise to add a delay in ms: Ex to wait 1 second: await delay(1000);.

Usage Example

The usage is very similar with the redux-saga, but replacing the generators with async functions and the call of Promises with await instead of yield:

Suppose we have a UI to fetch some user data from a remote server when a button is clicked. (For brevity, we'll just show the action triggering code.)

class UserComponent extends React.Component {
  ...
  onSomeButtonClicked() {
    const { userId, dispatch } = this.props
    dispatch({type: 'USER_FETCH_REQUESTED', payload: {userId}})
  }
  ...
}

The Component dispatches a plain Object action to the Store. We'll create a Saga that watches for all USER_FETCH_REQUESTED actions and triggers an API call to fetch the user data.

sagas.js

import { dispatch, takeEvery } from 'redux-sagas-async'
import Api from '...'

// worker Saga: will be fired on USER_FETCH_REQUESTED actions
const fetchUser = async (action) {
   try {
      const user = await Api.fetchUser(action.payload.userId);
      dispatch({type: "USER_FETCH_SUCCEEDED", user: user});
   } catch (e) {
      dispatch({type: "USER_FETCH_FAILED", message: e.message});
   }
}

/*
  Starts fetchUser on each dispatched `USER_FETCH_REQUESTED` action.
  Allows concurrent fetches of user.
*/
export default mySaga = () => {
  takeEvery("USER_FETCH_REQUESTED", fetchUser);
}

To run our Saga, we'll have to connect it to the Redux Store using the redux-sagas-async middleware.

main.js

import { createStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-sagas-async';

import reducer from './reducers';
import mySaga from './sagas';

// create the saga middleware
const sagaMiddleware = createSagaMiddleware(() => {
  mySaga();
  // error function is optional
}, (error) => console.log('global Saga error', error));

// mount it on the Store
const store = createStore(
  reducer,
  applyMiddleware(sagaMiddleware)
);

// render the application