📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

simple-api-call-life-cycle

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-api-call-life-cycle

make api call with redux

1.0.5
Source
npm
Version published
Weekly downloads
2
-92%
Maintainers
1
Weekly downloads
 
Created
Source

simple-api-call-life-cycle

NPM version

Install

$ npm install simple-api-call-life-cycle --save

Usage

$ A api call lifecycle library for redux combined with redux thunk to be reused for the entire project,
from action to reducer.

action.

import { apiCall } from 'simple-api-call-life-cycle';
// Passing the type and define the action.
const FETCH_PRODUCTS = 'FETCH_PRODUCTS';
const fetchProductsAction = new apiCall(FETCH_PRODUCTS);
const fetchProductsRequest = axios.get('url');

export const fetchProducts = fetchProductsAction.fetch.bind(
  fetchProductsAction,
  fetchProductsRequest
);
export { fetchProductsAction };

reducer.

import { fetchProductsAction } from '../actions';

const INITIAL_STATE = {
  isInProgress: undefined,
  isCompleted: undefined,
  hasFailed: undefined,
  products: []
};

export default (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case fetchProductsAction.init:
    // set loading to be true.
    case fetchProductsAction.success:
    // Promise resolved
    case fetchProductsAction.fail:
    //
    default:
      return state;
  }
};

components.

if(!state.isCompleted) {
  fetchProducts();
}
if(this.props.state.isInProgress && !nextProps.state.isCompleted) {
  fetchProducts()
}
if(!state.isCompleted || state.isInProgress) {
  return <loader />
}

FAQs

Package last updated on 19 Jul 2018

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