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

v1.1.0

Published

An action creator for Redux Saga compatible with Redux Form. Forked from mhssmnn/redux-form-saga

Downloads

138

Readme

Newer version

Idea of redux-saga-actions has been reworked and published as redux-saga-routines. Before using this package, please take a look at new one!

redux-saga-actions

An action creator for Redux Saga compatible with Redux Form. Forked from redux-form-saga

Why do I need this?

Reduce boilerplate from your source code when making requests to API or validating forms build on top of Redux Form.

Installation

yarn add redux-saga-actions

Important! redux-saga-actions uses native ES2015 Promises, if the browser you are targeting doesn't support ES2015 Promises, you have provide a valid polyfill, such as the one provided by babel.

Usage

First of all to enable redux-saga-actions, you have to add actionsWatcherSaga in your sagaMiddleware.run(), for example like this:

const sagas = [yourFirstSaga, yourOtherSaga, ..., actionsWatcherSaga];
sagas.map(sagaMiddleware.run);

Then, use createAction to in your code:

import { createAction } from 'redux-saga-actions';

// create action
const action = createAction('FETCH_DATA');

// now your action is a function that returns promise (useful for Redux Form users)
// action == (payload, dispatch) => Promise

// also, you have access to sub action types constants:
// action.REQUEST == 'FETCH_DATA_REQUEST';
// action.SUCCESS == 'FETCH_DATA_SUCCESS';
// action.FAILURE == 'FETCH_DATA_FAILURE';

// and to of sub actions creators:
// action.request(payload) == { type: 'FETCH_DATA_REQUEST', payload };
// action.success(payload) == { type: 'FETCH_DATA_SUCCESS', payload };
// action.failure(payload) == { type: 'FETCH_DATA_FAILURE', payload };


// when you want to initialize data fetching, you need only to call action:
action(payload, dispatch);

// then, you need to handle action.REQUEST action in your own saga to perform API request:
function handleRequest() {
  try {
    // perform request to '/some_url' to fetch some data
    const response = yield call(apiClient.request, '/some_url');
    // if request successfully finished
    yield put(action.success(response.data));
  } catch (error) {
    // if request failed
    yield put(action.failure(response.error));
  }
}

function* handleRequestSaga() {
  yield takeEvery(action.REQUEST, handleRequest)
}

Result of action(payload, dispatch) is a Promise, so you can directly pass this function to Redux Form's handleSubmit to perform async validation:

<form onSubmit={handleSubmit(action)}>...</form>

To properly handle form errors you have to pass to action.failure instance of SubmissionError:

yield put(action.failure(new SubmissionError(response.error)));

Migration from redux-form-saga:

This package is 100% compatible with [email protected], so feel free to use it:

// you can either use old constants and function names:
import { PROMISE, createFormAction, formActionSaga } from 'redux-saga-actions';

// or new if you want:
import { PROMISE_ACTION, createAction, actionsWatcherSaga } from 'redux-saga-actions';

Scripts

$ npm run test

License

MIT