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

redux-reloaded

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-reloaded

![advertisement](https://raw.githubusercontent.com/ginger-io/redux-reloaded/master/advertisement.jpg)

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
93
decreased by-44.64%
Maintainers
1
Weekly downloads
 
Created
Source

Redux Reloaded

advertisement

What's this?

Typesafe Redux, without all the boilerplate...and more.

Features

Less Boilerplate


import { createAction, createReducer } from "redux-reloaded"

/** Define all your actions in an Enum  */
export enum Actions {
  SELECT_PATIENT = "SELECT_PATIENT"
}

/**  Create what Redux calls an "Action Creator" - i.e. a function that returns an action  */
export const selectPatient = createAction(
  Actions.SELECT_PATIENT,
  (id: string) => ({
    patientId: id
  })
)


/** Create a reducer that operates on State, with some initial state */
type State = {}
export const reducer = createReducer<State>({
  selectedPatientId: null
})

/** And when we see the selectPatient action, update our State... */
reducer.on(selectPatient, (state, { payload }) => ({
  ...state,
  selectedPatientId: payload.patientId
}))

Async Action Handlers

Often you want to take some async action based on a Redux event - e.g. call an API, wait for the response and update the UI at a later time. That's what redux-thunk and redux-saga are for.

But both of those options have their tradeoffs. redux-reloaded aims to be easy to use and simple to test. It's just like DOM event-listeners, but for Redux events. You bind a "handler" to your event, and it runs every time that event is triggered.


import { createActionHandlers, createActionHandlerMiddleware } from "redux-reloaded"
import { applyMiddleware, createStore } from "redux"

// Stick objects you want your async acion your services
type Services = {
    apiClient: APIClient
}

const services: Services = ...

type State = {
}

export const actionHandlers = createActionHandlers<Services, State>()
actionHandlers.on(selectPatient, async ({ action, context, redux }) => {
    const foo = await context.apiClient.getFoo()
    redux.dispatch(...)
})


export const store = createStore(
  rootReducer,
  undefined,
  applyMiddleware(
    createActionHandlerMiddleware({ services }, [actionHandlers])
  )
)

FAQs

Package last updated on 11 Feb 2020

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