You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@redux-requests/promise

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@redux-requests/promise

Promise driver for Redux-Requests, Redux addon to simplify AJAX requests

0.1.1
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@redux-requests/promise

npm version Build Status Coverage Status Known Vulnerabilities lerna

Promise driver to Redux - addon to simplify handling of AJAX requests.

Installation

To install the package, just run:

$ npm install @redux-requests/promise

Usage

This driver is useful, when you use an API library, which use promises.

For instance, you could do something like that:

import { createDriver } from '@redux-requests/promise';

handleRequests({
  driver: createDriver({
    AbortController: window.AbortController,
    processResponse: response =>  ({ data: response }),
  }),
});

const fetchPhoto = id => ({
  type: FETCH_PHOTO,
  request: {
    promise: axios.get(`https://jsonplaceholder.typicode.com/photos/${id}`),
  },
});

AbortController is optional, by default is will use AbortController is available, with fallback to DummyAbortController which does nothing. If your invironment doesn't support AbortController, you could pass a polyfill. If you don't, requests abort won't work.

processResponse is also optional, the default is response => ({ data: response }), it is useful if your promises resolve to more things than data, then you could for instance use response => ({ data: response.data })

For usage, see redux-saga-requests docs.

Also note, that for mutations you need to pass meta.asMutation: true in your request actions, so core library could know whether a request is a query or a mutation.

Licence

MIT

Keywords

redux

FAQs

Package last updated on 29 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts