All Projects → Justinidlerz → saga-action-creator

Justinidlerz / saga-action-creator

Licence: MIT license
An opinionated lib to create actions for Redux-saga

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to saga-action-creator

etoolbox
Collection of web developer utilities packaged as a desktop app. Technologies: React, Typescript, Redux, Axios, React-Query, Electron
Stars: ✭ 95 (+427.78%)
Mutual labels:  redux-saga
nextjs-ts-antd-redux-storybook-starter
🏃🏼 Next.js + TypeScript + Ant Design + Redux Toolkit + Redux Saga + Styled Components + Jest + Storybook 企业级项目脚手架模板
Stars: ✭ 78 (+333.33%)
Mutual labels:  redux-saga
next-ifood
Ifood clone made with NextJS ⚛️
Stars: ✭ 68 (+277.78%)
Mutual labels:  redux-saga
react-redux-hackernews
React Redux Hackernews Application
Stars: ✭ 19 (+5.56%)
Mutual labels:  redux-saga
react-truffle-metamask
Build an DApp using react, redux, saga, truffle, metamask
Stars: ✭ 25 (+38.89%)
Mutual labels:  redux-saga
spotify-release-list
📅 Display list of Spotify releases from artists you follow
Stars: ✭ 142 (+688.89%)
Mutual labels:  redux-saga
Arc
React starter kit based on Atomic Design
Stars: ✭ 2,780 (+15344.44%)
Mutual labels:  redux-saga
react-boilerplate-ssr
ssr react boilerplate
Stars: ✭ 25 (+38.89%)
Mutual labels:  redux-saga
redux-saga-callback
redux-saga helper functions to await dispatched actions
Stars: ✭ 19 (+5.56%)
Mutual labels:  redux-saga
media-library
An online media library application with React, Redux and redux-saga
Stars: ✭ 27 (+50%)
Mutual labels:  redux-saga
head-start
A boilerplate for React applications with an Express backend with a simple user registration/login
Stars: ✭ 24 (+33.33%)
Mutual labels:  redux-saga
fractal-component
A javascript library that can help you to encapsulate decoupled UI component easily
Stars: ✭ 13 (-27.78%)
Mutual labels:  redux-saga
webservices
Prestashop Web Services + React JS App
Stars: ✭ 34 (+88.89%)
Mutual labels:  redux-saga
react-template
My starting template for most react apps
Stars: ✭ 23 (+27.78%)
Mutual labels:  redux-saga
ts-ui
Telar Social Network using Reactjs
Stars: ✭ 35 (+94.44%)
Mutual labels:  redux-saga
handwritten-digit-recognition-tensorflowjs
In-Browser Digit recognition with Tensorflow.js and React using Mnist dataset
Stars: ✭ 40 (+122.22%)
Mutual labels:  redux-saga
dont-waste-your-ducking-time
🐓 An opinionated guide on how to test Redux ducks
Stars: ✭ 28 (+55.56%)
Mutual labels:  redux-saga
react admin
🎉 TS+Hooks 后台管理系统 http://hooks.sunhang.top
Stars: ✭ 39 (+116.67%)
Mutual labels:  redux-saga
pokedex
Aplicação desenvolvida com a Pokedéx API
Stars: ✭ 33 (+83.33%)
Mutual labels:  redux-saga
Project06-A-Slack
팀 협업도구, 우리동네 슬랙 🚀
Stars: ✭ 14 (-22.22%)
Mutual labels:  redux-saga

Saga action creator

npm version codecov npm Build Status TypeScript Tested with Jest MIT License

The Saga-action-creator is made to simplify the writing of Redux-saga, it can auto-generate Action Creators for dispatch from your writes Saga effects directly.

This toolkit supports plugins and It can help to make some actions before and after effect convenient, which means it will be much simpler to set up the loading state, handle the error, etc. when you executing the asynchronous effect.

Adds automated loading indicators for effects to Saga-action-creator. Inspired by Rematch.

Why we still need this toolkit when we have rematch already? That is because the cost of migration from Redux's historical project to Rematch is high, and Redux-Saga has many excellent designs (i.e: such as take, fork, channel, etc.).

Features

  • Auto-generate actions from passed effect
  • Completely retain redux-saga features
  • Support plugins
  • Typescript-typings support (including plugins)
  • Testable

Getting started

Install

$ npm install --save saga-action-creator

or

$ yarn add saga-action-creator

Usage Example

Step 1: Define saga effects

import createSagaActions from 'saga-action-creator';
import { takeLatest, call } from 'redux-saga/effects';
import { getUserInfo, updateUser } from '../services/user';

const user = createSagaActions({
  // By default, you can pass the generator functions
  *getUserById(id: string): Generator<any, any, any> {
    yield call(getUserInfo, id);
  },
  // If you need to change the effect take type
  // you can pass the object for the action name
  updateUser: {
    takeType: takeLatest,
    *effect(id: string, name: string): Generator<any, any, any> {
      yield call(updateUser, id, { name });
    },
  },
});

export default user;

Step 2: Connect sagaActions

import { createConnection, getLoadingPlugin } from 'saga-action-creator';
import user from './user';
import { takeLatest } from 'redux-saga/effects';

const creator = createConnection({
  // Combine creators
  creators: {
    user,
  },
  // You can change the default take type here,
  // by default is `takeEvery`
  defaultTakeType: takeLatest,
  // You can pass plugins at there
  plugins: {
    // the plugin name will be map to reducer key
    loading: getLoadingPlugin(),
  },
});

export default creator;

For a more advanced setup, see plugins and Redux-saga

Step 3: Connect to redux and redux-saga

import { createStore, combineReducers, applyMiddleware } from 'redux';
import { all } from 'redux-saga/effects';
import createSagaMiddleware from 'redux-saga';
import creator from '../sagas';

// connect to store
const reducers = combineReducers({
  ...creator.getReducers(),
});

const sagaMiddleware = createSagaMiddleware();

// connect to saga and run
sagaMiddleware.run(function*() {
  yield all(creator.getEffects());
});

const store = createStore(reducers, applyMiddleware(sagaMiddleware));

export type AppState = ReturnType<typeof reducers>;

export default store;

Step 3: Use created actions

import { connect } from 'react-redux';
import { AppState } from '../store';
import userActions from '../sagaActions/user';
import UserList from './UserList';

const mapStateToProps = (state: AppState) => ({
  loading: state.loading.user.getUserById,
});

const mapDispatchToProps = {
  getUserById: userActions.actions.getUserById,
};

export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(UserList);

Examples

TODOs

  • Typescript generic types for plugins export reducer
  • Code remarks
  • Unit tests
  • Local example
  • Plugin docs
  • Online examples
  • API docs
  • Chinese docs

API

See the APIs

License

For a detailed explanation on how things work, checkout the rollup doc and parcel

Copyright (c) 2019-present, Idler.zhu

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