Giter Club home page Giter Club logo

react-project-legacy-'s Introduction

React

This project acts as a template for front-end application's using React and Redux, along with several other tools and technologies.

It embodies a rather extensive amount of research into this style of architecture and attempts to create an opinionated structure for building on. Additionally, our hope is that this can act as a kicking off point for beginners of React or as a solid base to those who already have some experience.

What's Being Used?
  • React for managing the presentation logic of your application.
  • Redux for generating and managing your state model.
  • Portals for making AJAX calls to a server.
  • Stylus + Helpful UI for stylesheet compilation.
  • Gulp for handling automated tasks.
  • Babel for compiling ES2015+ down to ES5 compatible code. Additionally, this project is set up to support type checking using Flow syntax.
  • WebPack for bundling code down to a single file and enabling hot module reloading.
  • Express for serving up the development server.
  • Mocha + Chai for testing.

Getting Started

In order to get started developing, you'll need to do a few things first.

  1. Install all of the node_modules required for the package. Depending on your computer's configuration, you may need to prefix this command with a sudo.
npm install

or

sudo npm install
  1. Create your .env environment file by making a duplicate of the .env-example and remove the -example. In the .env file, you can set environment related variables like your API_HOST or APP_ENV.
APP_ENV=local
API_HOST=http://localhost:9700/fake-api
  1. Lastly, run the start command to get the project off the ground. This command will not only build your JS files using the Webpack dev-server, but it will also auto-compile your Stylus files on every .styl file save.
npm start
  1. Head over to http://localhost:9700 to see your app live!

File Structure

build/

This is where your application will be compiled. Assets, like images and fonts, should be placed directly within this folder. Also in this folder is a default index.html file for serving up the application.

src/

The client folder houses the client application for your project. This is where your client-side Javascript components (and their directly accompanying styles) live.

test/

Your unit and integration tests for components, reducers and services. It is not really necessary to test action creators or contexts (unless you really want to).

App Components

Actions

These are your Redux action creators. There are 2 styles of action creators: direct and deferred.

Direct
export function directAction (/* params */) {
  return { type: 'ACTION_NAME', ... };
}
Deferred
export function deferredAction (/* params */) {
  return function (dispatch) {
    dispatch({ type: 'ACTION_NAME', ... });
  };
}

Components

Your React components along with their accompanying Stylus files. React components should be kept "dumb" and have no knowledge of the Redux state model. Build your React components to accept "hook" methods that can be passed in externally.

For example, if your component needs to dispatch an action when the user clicks a button, simply write this method to invoke a property that can be passed in.

render () {
  return (
    <button onClick={this.props.onButtonClick}>Fire Some Action</button>
  );
}

Contexts

Contexts allow you to hook up "dumb" components to your Redux state model. This is essentially the glue between your state model and presentation logic.

Reducers

Your Redux reducers that will generate your state model.

Services

Singletons, classes and utilities that can be used by any part of your application.

react-project-legacy-'s People

Contributors

brunnerjosh avatar nickglenn avatar tannerjepsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-project-legacy-'s Issues

Better AJAX Implementation

Unless proven otherwise, I believe it may be ideal to implement an AJAX solution that allows global options to be set. This way, variables such as server hostname or user token don't have to be constantly passed around to each action creator or component that uses it.

Note: Currently using superagent

Example

import Request from './services/Request'

Request.globals.hostname = 'http://someurl.com'
Request.globals.headers.Authorization = 'Bearer xxxxxxxx'

Form Validation Example

Forms can be kind of tricky in React + Flux, at least when it comes to form errors and validation. Adding a form example with input validation and/or server error would be super helpful.

Possible Resource

Auth redirection in actions or store?

Putting the authentication redirection in the action creators make sense but may be an issue if the store hasn't been updated before the next (possible guarded) route is loaded.

Example: I am logged in and want to log out.

  1. Upon logging out I should be redirected to the login page.
  2. If I am still logged in while hitting the login page, I should be redirected to the home page.
  3. Currently, the transitionTo('login') method is being called prior to dispatching the LOGOUT action.

This would mean that the logout action would redirect you to the login page, only for it to send you back to the home page and then possibly sending you back to the login page once store is updated.

Isomorphic React Support

Perform initial load on the Node server to allow for faster page loads and hack-free support for search engine crawling.

Stylus Support

Integrate stylus examples into the application along with recommended file structure for bundling styles with their related components. Ideally, it would be good to base this on the work we're doing internally with Helpful UI.

Also need to decide whether or not to allow JS to handle styling with import or use Gulp ahead of time to generate CSS based on the bootstrapping main.styl file we presently have.

Add server.js for production env

At the moment, this boilerplate is only ready for dev and not production. We did this for MHM but since I'm not aware what parts of that are MHM specific, I'll defer to our React Captains™ for this implementation.

File Structure Finalization + README

Need to solidify file structure and create an opinion based on common best practices for the file structure of components, stores, services, actions, etc. Once we have a standard created, we can begin publishing a README for it.

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.