New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lore-actions

Package Overview
Dependencies
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lore-actions

Blueprints to reduce boilerplate for Redux actions

  • 0.13.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
3
Weekly downloads
 
Created
Source

Installation

Lore-Actions is available as an npm package.

npm install lore-actions

After npm install, you'll find all the .js files in the /src folder and their compiled versions in the /lib folder.

Usage

lore-actions is an abstraction teir to reduce the boilerplate associated with making ajax calls in client side applications that use React and Redux. It works by defining a set of blueprints for standard REST calls for CRUD operations, and then leveraging those blueprints using a configuration file. Example configuration file:

module.exports = {
  blueprint: 'create',

  model: Todo,

  optimistic: {
    actionType: ActionTypes.ADD_TODO,
    payloadState: PayloadStates.CREATING
  },

  onSuccess: {
    actionType: ActionTypes.UPDATE_TODO,
    payloadState: PayloadStates.RESOLVED
  },

  onError: {
    actionType: ActionTypes.REMOVE_TODO,
    payloadState: PayloadStates.ERROR_CREATING,
    beforeDispatch: function(response, args){
      console.log({
        message: "Todo could not be created",
        response: response
      });
    }
  }
};

Configuration options are as follows:

blueprint [required]: can be one of create, destroy, fetch, or update

model [required]: A Backbone Model or Collection, or any function/object that abides by the Backbone interface (has fetch() and save() methods that return a promise).

optimistic [optional]: Action to emit before making an AJAX call to the server. Must be specified as a pair of strings called actionType and payloadState. These values will be picked up by the Redux reducers. actionType should be something like ADD_TODO or REMOVE_TODO (value is arbitrary but should be unique). payloadState should be something like FETCHING or ERROR_CREATING.

onSuccess [optional]: Action to emit if the AJAX call to the server is successful (returns a 200 level status code). Arguments are same as optimistic option.

onError [optional]: Action to emit if the AJAX call to the server fails (returns a non-200 level status code). Supports an optional beforeDispatch callback that allows you to handle the error case by notifying the user (such as through the console or through a toast or snack in the UI).

FAQs

Package last updated on 24 Jun 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