All Projects → sergeysova → redux-execute

sergeysova / redux-execute

Licence: other
Another way with thunk in redux

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to redux-execute

linkedin-clone-react-frontend
🚀 Frontend for a software similar to LinkedIn
Stars: ✭ 48 (+166.67%)
Mutual labels:  redux-thunk
crypto-markets
react-native-cryptocurrency-ticker
Stars: ✭ 27 (+50%)
Mutual labels:  redux-thunk
task-manager
Task Manager App
Stars: ✭ 19 (+5.56%)
Mutual labels:  redux-thunk
collateral
Map, find and isolate captured side effects
Stars: ✭ 39 (+116.67%)
Mutual labels:  side-effects
ParticleLib
一个用于Minecraft Particle的类库
Stars: ✭ 19 (+5.56%)
Mutual labels:  effect
cra-redux-boilerplate
⚛️🔨create-react-app application with redux and another cool libraries to make your life easier.
Stars: ✭ 15 (-16.67%)
Mutual labels:  redux-thunk
BrushEffect
This is a simple animation effect for any android view.
Stars: ✭ 23 (+27.78%)
Mutual labels:  effect
react-stateful-component
Functional stateful React components with sideEffect support
Stars: ✭ 19 (+5.56%)
Mutual labels:  side-effects
FunCrop
Video Split Effect: a lots of transition effect in a video.
Stars: ✭ 42 (+133.33%)
Mutual labels:  effect
Fakeflix
Not the usual clone that you can find on the web.
Stars: ✭ 4,429 (+24505.56%)
Mutual labels:  redux-thunk
SOUL-VA
The SOUL Virtual Analog Library
Stars: ✭ 45 (+150%)
Mutual labels:  effect
LegendaryExplorer
Editor toolset for Mass Effect Trilogy and Mass Effect Legendary Edition
Stars: ✭ 85 (+372.22%)
Mutual labels:  effect
image-hover
💄 No Javascript, image hover effects you've always wanted
Stars: ✭ 48 (+166.67%)
Mutual labels:  effect
react-theme
Production ready Wordpress theme built with React, Redux, Redux-Thunk, Intl, React Router v4, etc... and packaged by Webpack 2. Enjoy!
Stars: ✭ 14 (-22.22%)
Mutual labels:  redux-thunk
react-native-boilerplate
React Native Boilerplate - React Native Starter Kits : react-navigation and its dependencies, redux, redux persist and redux thunk, redux toolkit, react native vector icons, react-native async storage
Stars: ✭ 68 (+277.78%)
Mutual labels:  redux-thunk
elegant-react-ssr
Server-side rendering with create-react-app, React Router v4, Helmet, Redux, and Thunk boilerplate, without ejecting CRA
Stars: ✭ 16 (-11.11%)
Mutual labels:  redux-thunk
cerebro-web
Website for Cerebro
Stars: ✭ 21 (+16.67%)
Mutual labels:  redux-thunk
VideoSplice
Video splice effects.
Stars: ✭ 56 (+211.11%)
Mutual labels:  effect
trivin
⚡️Setup your entire project quickly and easily with 1-line command ⚡️
Stars: ✭ 58 (+222.22%)
Mutual labels:  redux-thunk
react-native-shopping-app
A shopping app using React Navigation, Redux, Redux-Thunk and Firebase.
Stars: ✭ 67 (+272.22%)
Mutual labels:  redux-thunk

redux-execute Maintainability Build Status Coverage Status

Readme

Installation

Note: redux-execute requires redux@^4.0.0

npm install --save redux-execute

ES modules:

import { createExecue } from "redux-execute"

CommonJS:

const { createExecue } = require("redux-execute")

Why do I need this?

Please, read introduction to thunks in Redux. Execue just another way to run and test thunks(effects).

Motivation

Redux Execue middleware allows you to write "action creators" that return function instead of an action. These action creators are called effects. The effect can be used to delay the dispatch an action, or to dispatch another effect, or to dispatch only if a certain condition is met. The inner function receives the store methods dispatch and getState as parameters.

An action creator that returns a function to perform asynchronous dispatch:

const setValue = (value) => ({
  type: "SET_VALUE",
  payload: { value },
})

const setValueWithDelay = (value) => (dispatch) => {
  setTimeout(() => {
    // classic dispatch action
    dispatch(setValue(value))
  }, 1000)
}

Effect that dispatch another effect:

const incrementWithDelay = () => (dispatch, getState) => {
  const { value } = getState()

  // Just pass effect and all arguments as arguments of dispatch
  dispatch(setValueWithDelay, value + 1)
}

What is an effect?

An effect is a thunk that called by dispatch.

const effect = (a, b) => (dispatch, getState) => {
  return a + b
}

store.dispatch(effect, 1, 2) // 3

See also

Composition

Any return value from the inner function of effect will be available as the return value of dispatch itself. This is convenient for orchestrating an asynchronous control flow with effects dispatching each other and returning Promises to wait for each other's completion.

const requestGet = (url) => () =>
  fetch(`/api${url}`).then((response) => response.json())

const userPostsFetch = (userId) => async (dispatch) => {
  const user = await dispatch(requestGet, `/users/${userId}`)

  if (user.isActive) {
    return dispatch(requestGet, `/users/${userId}/posts`)
  }

  return []
}

Logger

Redux Execue has logger out of the box. You can combine it with redux-logger:

import { createStore, applyMiddleware } from "redux"
import { createLogger } from "redux-logger"
import { createExecue } from "redux-execute"

import { rootReducer } from "./reducers"

const store = createStore(
  rootReducer,
  applyMiddleware(
    createExecue({ log: true }),
    createLogger({ collapsed: true }),
  ),
)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].