Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-json-api-handlers

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-json-api-handlers

JSON-API entities and relationships handlers

  • 2.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
65
decreased by-18.75%
Maintainers
1
Weekly downloads
 
Created
Source

redux-json-api-handlers

Redux JSON-API handlers V2. New api

Api methods

createLoadHandler(resourceType: string, options: object): nextState

Use it for handle success data loading

Options:

const options = {
  mapToKey: bool|string,  // default: false, map result to custom reducer key
  withLoading: bool,      // default: true, enable/disable loading params
  singular: bool,         // default: false, get first value and store it
  withReplace: bool,      // default: false, replace current values instead of merge it
  addToState: object,     // default: {}, additional props passed to state
}
Simple example

Initial state looks like:

state = {
  posts: {
    isLoaded: false,
    isLoading: false,
    posts: {}
  }
}
const handlers = {
  [LOAD_POSTS.SUCCESS]: createLoadHandler('posts')
}

Resulted state looks like:

state = {
  posts: {
    isLoaded: true,
    isLoading: false,
    posts: [1]
  }
}
Custom example

Initial state looks like:

state = {
  posts: {
    isLoadedPostIds: false,
    isLoadingPostIds: false,
    post: null,
  }
}

Handler:

const handlers = {
  [LOAD_POSTS.SUCCESS]: createLoadHandler('posts', { mapToKey: 'post', singular: true })
}

Resulted state looks like:

state = {
  posts: {
    isLoadedPostIds: true,
    isLoadingPostIds: false,
    postIds: 1,
  }
}

createDeleteHandler(stateKey: string): nextState

Use it for handle delete data.

Action payload should have deletedId param

Simple example

Initial state looks like:

state = {
  posts: {
    posts: [1, 2]
  }
}

Handler:

const handlers = {
  [DELETE_POST.SUCCESS]: createDeleteHandler('posts')
}

Resulted state looks like:

state = {
  posts: {
    posts: [2]
  }
}
Custom example

Initial state looks like:

state = {
  posts: {
    postIds: [1, 2]
  }
}
const handlers = {
  [DELETE_POST.SUCCESS]: createDeleteHandler('posts', {
    mapToKey: 'postIds',
  })
}

Resulted state looks like:

state = {
  posts: {
    postIds: [1]
  }
}

FAQs

Package last updated on 12 Feb 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc