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

fetchum-redux

v2.7.0

Published

Redux actions for fetchum

Downloads

45

Readme

Fetchum Redux

Redux Actions for Fetchum

Downloads Downloads NPM Version Dependencies Dev Dependencies License

Install

npm i -S fetchum-redux

Api - generateRequest

generateRequest returns a fetchum generateRequest wrapped in a thunk action.

When then returned function is called it will trigger 2 actions. First 'NEW_FETCH_REQUEST' then 'FETCH_REQUEST_SUCCESS' if successful and 'FETCH_REQUEST_FAILURE' if not.

Examples

This example assumes redux-thunk is being used

import { generateRequest } from 'fetchum-redux';

const getRandomUserReq = generateRequest({
  method: 'GET',
  external: true,
  route: 'http://uifaces.com/api/v1/random',
});

const getRandomUser = () => {
  dispatch(getRandomUserReq())
    .then(res => console.log(res.data))
    .catch(res => console.error(res));
};

If you dont want to use redux-thunk then use like so:

import { generateRequest } from 'fetchum-redux';

const getRandomUserReq = generateRequest({
  method: 'GET',
  external: true,
  route: 'http://uifaces.com/api/v1/random',
});

const getRandomUser = () => {
  getRandomUserReq()(dispatch)
    .then(res => console.log(res.data))
    .catch(res => console.error(res));
};

Api - generateCRUDRequests

Return exactly like generateCRUDRequests from Fetchum but uses fetchum-redux generateRequest and passes a modify type param.

  • fetchAll adds FETCH_ALL to the type eg: 'NEW_FETCH_ALL_FETCH_REQUEST' 'FETCH_ALL_FETCH_REQUEST_SUCCESS'
  • fetchOne adds FETCH_ONE
  • create adds CREATE
  • update adds UPDATE
  • delete adds DELETE

Api - basic Calls

All of fetchum's basic calls work as well like so:

import { apiRequests } from 'fetchum-redux';

const getUsersDirect = () => {
  apiRequests.get('/v1/users')(dispatch)
    .then((res) => { console.log('my users', res.data); })
    .catch((res, err) => { console.warn(res); });
};

const getUsersDirectWithThunk = () => {
  dispatch(apiRequests.get('/v1/users'))
    .then((res) => { console.log('my users', res.data); })
    .catch((res, err) => { console.warn(res); });
};

Modifying action types

Each method also takes an extra parameter at the end to use to modify the action type names. The name parameter replaces the word 'FETCH' in the action type like so:

generateRequest looks like generateRequest({}, 'TEST') and the action types will be: First 'NEW_TEST_REQUEST' then 'TEST_REQUEST_SUCCESS' if successful and 'TEST_REQUEST_FAILURE' if not.

generateCRUDRequests keeps its individual additions noted above but still overrides the word 'FETCH'. For example generateCRUDRequests('/users', 'id', true, 'USERS') for a fetchOne would trigger first 'NEW_FETCH_ONE_USERS_REQUEST' then 'FETCH_ONE_USERS_REQUEST_SUCCESS' if successful and 'FETCH_ONE_USERS_REQUEST_FAILURE' if not.