Git Product home page Git Product logo

retreon

A type-safe, batteries-included redux toolkit.

Build status npm npm bundle size


Project Status

⛔ UNMAINTAINED

State management is still heavily evolving in React. While I believe Retreon is one of the best ways to use Redux, the community is modernizing towards modular hook-based libraries.

I would recommend exploring Recoil, Jotai, or any of the newer approaches.

Purpose

Redux is a phenomenally powerful tool, and it can be a true joy to work with. But it takes time to find good tooling and develop healthy patterns.

Retreon aims to provide good patterns and strong types out of the box, including tools for async actions and error handling. Retreon is FSA compliant.

Here's a taste:

// actions.ts
const fetchResource = createAction.async('fetch-resource', async (id: number) => {
  const response = await fetch(`/resources/${id}`)
  return response.json()
})
// reducer.ts
const reducer = createReducer(initialState, handleAction => [
  // Called as soon as the action starts
  handleAction.optimistic(fetchResource, (state, resourceId) => {
    state.loading = true
  }),

  // Optionally, handle errors if your action fails
  handleAction.error(fetchResource, (state, error) => {
    state.loading = false
  }),

  // Called when the action's promise resolves, passing the payload
  handleAction(fetchResource, (state, resource) => {
    state.loading = false
    state.resource = resource
  }),
])

If you prefer to learn by example, take a gander at the examples directory, or check out TodoMVC to see a functioning application.

Installation

Retreon can be installed through npm.

# NPM
npm install retreon

# Yarn
yarn add retreon

Retreon depends on middleware to implement async actions and error handling. Once it's installed, register it with your redux store:

// Wherever you create your redux store...
import { middleware } from 'retreon'

createStore(reducer, applyMiddleware(middleware))

Documentation

Documentation is hosted on the retreon website:


Retreon is inspired by redux-actions and immer.

Retreon's Projects

retreon icon retreon

A type-safe, batteries-included redux toolkit.

todomvc icon todomvc

A todo list app built with retreon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.