Giter Site home page Giter Site logo

fossabot / uptrend-redux-modules Goto Github PK

View Code? Open in Web Editor NEW

This project forked from uptrend-tech/uptrend-redux-modules

0.0 0.0 0.0 197 KB

Collection of modules useful to redux based react apps.

License: MIT License

Emacs Lisp 0.09% JavaScript 99.91%

uptrend-redux-modules's Introduction

uptrend-redux-modules

Redux Module (redux + redux-saga + redux-saga-thunk) for requesting resources from API and storing response data into entities if provided a normalizr schema.


Build Status Code Coverage version downloads MIT License

All Contributors PRs Welcome Code of Conduct FOSSA Status

Watch on GitHub Star on GitHub Tweet

The problem

// TODO

This solution

// TODO

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

yarn add uptrend-redux-modules

Example Project Usage

Using uptrend-redux-modules requires some ceremony. Below is an example of how one may set it up in a react app using the resource and entities redux-modules.

Do note there are many ways you could organize your project and this example is not strict guidelines by any means.

Resource & Entities

  • src/store/modules/resource/index.js

    // - src/store/modules/resource/index.js
    import {createResource} from 'uptrend-redux-modules'
    
    // createResource(...) => { actions, reducers, sagas, selectors }
    export default createResource()
  • src/store/modules/entities/index.js

    // - src/store/modules/entities/index.js
    import {createEntities} from 'uptrend-redux-modules'
    import schemas from './schemas'
    
    // createEntities(...) => { actions, middleware, reducers, sagas, selectors }
    export default createEntities({schemas})
  • src/store/modules/entities/schema.js

    // - src/store/modules/entities/schemas.js
    import {schema} from 'normalizr'
    
    export const user = new schema.Entity('users')
    export const team = new schema.Entity('teams', {owner: user, members: [user]})
  • src/store/actions.js

    // - src/store/actions.js
    import {actions as entities} from 'src/store/modules/entities';
    import {actions as resource} from 'src/store/modules/resource';
    
    export {
      ...entities,
      ...resource,
    }
  • src/store/middlewares.js

    // - src/store/middlewares.js
    import {middleware as entities} from 'src/store/modules/entities'
    
    export default [
      // redux-modules middlewares
      entities,
    ]
  • src/store/reducers.js

    // - src/store/reducer.js
    import {combineReducers} from 'redux'
    
    import {reducer as entities} from 'src/store/modules/entities'
    import {reducer as resource} from 'src/store/modules/resource'
    
    export default combineReducers({
      entities,
      resource,
    })
  • src/store/sagas.js

    // - src/store/sagas.js
    import {sagas as entities} from 'src/store/modules/entities'
    import {sagas as resource} from 'src/store/modules/resource'
    
    // single entry point to start all Sagas at once
    export default function*(services = {}) {
      try {
        yield all([
          // app specific sagas
          example(services),
    
          // redux-modules sagas
          entities(services),
          resource(services),
        ])
      } catch (error) {
        console.error('ROOT SAGA ERROR!!!', error)
        console.trace()
      }
    }
  • src/store/selectors.js

    // - src/store/selectors.js
    import {selectors as fromEntities} from 'src/store/modules/entities'
    import {selectors as fromResource} from 'src/store/modules/resource'
    
    export {fromEntities, fromResource}

Usage

// TODO

Inspiration

Organizing actions, reducers, selectors, sagas, etc. into a module is based on redux-modules from Diego Haz.

The resource and entities modules specifically are modified version of those found in redux-modules and ARc.js.

Other Solutions

I'm not aware of any, if you are please make a pull request and add it here!

Contributors


Brandon Orther

๐Ÿ’ป ๐Ÿš‡ โš ๏ธ ๐Ÿ’ก

Dylan Foster

๐Ÿ› ๐Ÿค”

Thanks goes to these people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

FOSSA Status

uptrend-redux-modules's People

Contributors

fossabot avatar orther avatar

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.