Coder Social home page Coder Social logo

kettanaito / redux-dynamics Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 316 KB

Strongly-typed collection of tools to make your Redux workflow more dynamic.

License: MIT License

JavaScript 67.19% TypeScript 32.81%
redux redux-dynamics reducer-creation strongly-typed flow-typed

redux-dynamics's Introduction

Package version Build Status Coverage Status Dependencies Status

redux-dynamics

Strongly-typed collection of useful tools to make your Redux workflow more dynamic.

Features

Reducers

  • No huge switch statements!
  • state is always immutable
  • action is always immutable
  • context shared between all subscriptions
  • Declarative reducer subscriptions to the actions
  • Encouraging pure resolver functions
  • Support of RegExp as the expected action type

Getting started

Install

NPM:

npm install redux-dynamics --save

Yarn:

yarn add redux-dynamics

Create a reducer

// ./store/comments/index.js
import { Reducer } from 'redux-dynamics';

/* Create a new reducer with initial state */
const reducer = new Reducer({
  likes: 0
});

/* Subscribe to different actions */
reducer.subscribe('ADD_LIKE', (state, action, context) => {
  /* Note how both "state" and "action" are immutable */
  const nextLikes = state.get('likes') + action.get('amount');

  /* Resolve the next state */
  return state.set('likes', nextLikes);
});

reducer.subscribe('ACTION_TYPE', (state, action, context) => state);

export default reducer;

Connect to Redux

// ./store/reducer.js
import { createReducer } from 'redux';
import commentsReducer from './comments';

export default createReducer({
  /* Convert "Reducer" class into pure reducer function */
  comments: commentsReducer.toFunction()
});

Documentation

For more details on methods, usage examples and troubleshooting see the Documentation.

Contributing

Feel free to submit your ideas on enhanced Redux workflow by issuing a Pull request.

In case you have discovered a bug, outdated documentation or any other mismatch, please create a new Issue.

License

This library is licensed under MIT license.

redux-dynamics's People

Contributors

kettanaito avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

md-azam12

redux-dynamics's Issues

Flow - Strip interfaces

What

It is required to strip Flow types/annotations/interfaces from the /src source files.

Why

Not everybody uses Flow, or type checking in general. This library does not have a goal to force developers to use the latter.

How

  • During babel-loader transforms, using dedicated plugins
  • Webpack config: ignore /interfaces during bundling process

Expected behaviour

Static type checking should remain for development process of the library, but should not interfere with the end usage.

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.