0.13.0 • Published 7 years ago

lore-actions v0.13.0

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

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).

0.13.0

7 years ago

0.13.0-rc.2

7 years ago

0.13.0-rc.1

7 years ago

0.13.0-beta.16

7 years ago

0.13.0-beta.15

7 years ago

0.13.0-beta.14

7 years ago

0.13.0-beta.13

7 years ago

0.13.0-beta.12

7 years ago

0.13.0-beta.11

7 years ago

0.13.0-beta.10

8 years ago

0.13.0-beta.9

8 years ago

0.13.0-beta.7

8 years ago

0.13.0-beta.6

8 years ago

0.13.0-beta.5

8 years ago

0.13.0-beta.4

8 years ago

0.13.0-beta.3

8 years ago

0.13.0-beta.2

8 years ago

0.13.0-beta.1

8 years ago

0.12.7-rc.1

8 years ago

0.12.6

8 years ago

0.12.5

8 years ago

0.12.0

8 years ago

0.12.0-rc.1

8 years ago

0.11.5

8 years ago

0.12.0-beta.1

8 years ago

0.11.0

8 years ago

0.11.0-rc.1

8 years ago

0.11.0-beta.1

9 years ago

0.10.0

9 years ago

0.10.0-beta.1

9 years ago

0.9.0

9 years ago

0.8.0

9 years ago

0.7.0

9 years ago

0.6.30

9 years ago

0.6.28

9 years ago

0.6.27

9 years ago

0.6.16

9 years ago

0.6.12

9 years ago

0.4.0

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago