Giter Site home page Giter Site logo

lemoncode / react-typescript-samples Goto Github PK

View Code? Open in Web Editor NEW
1.8K 78.0 399.0 1.31 MB

The goal of this project is to provide a set of simple samples, providing and step by step guide to start working with React and Typescript.

License: MIT License

CSS 2.35% HTML 0.92% TypeScript 86.26% JavaScript 10.47%

react-typescript-samples's Issues

About page sample 01 Hello React

Proposal ( @nasdan to complete it):
#1 Hello React

This sample takes as starting point sample "00 Boiler plate", we add on top of that sample a simple react render.

In order to launch this project, follow this steps

TODO: Add all the steps here, npm install...
npm start

Then open your browser and navigate to: http://localhost:8080

Highlights

The most interesting parts worth to take a look:

  • index.ts: react + reactDom imports and simple dom render.

Update sample 02 Components

UPgrade to typescript 2.0, update libraries to latest version, remove typings, review set state and other pitfalls.

No need for readme.md, just a good review and get all uptodate and remove errors.

Update sample 01 Hello React

Update dependencies, typescript version and react versions, remove typings and make use of stateless components...

About page sample 03 Navigation

Proposal ( @nasdan to complete it):
#3 Navigation

This sample takes as starting point sample "02 Components".

We are adding page navigation to this project:

  • We have added two pages (about, members).
  • The user can navigate by cliking on links in a common navbar.

We are using react-router for the navigation support.

In order to launch this project, follow this steps

TODO: Add all the steps here, npm install...
npm start

Then open your browser and navigate to: http://localhost:8080

Highlights

The most interesting parts worth to take a look:

  • index.ts: routes configuration.
  • header.tsx: navigation links.
  • app.tsx: header + page container.
  • aboutPage.tsx / members.tsx: pages.

About page sample 02 Components

#2 Components

This sample takes as starting point sample "01 Hello react".

We are adding react components: a main component that consumes a header and aboutPage component.

In order to launch this project, follow this steps

TODO: Add all the steps here, npm install...
npm start

Then open your browser and navigate to: http://localhost:8080

Highlights

The most interesting parts worth to take a look:

  • app.tsx: main component, instantiates header and common component.
  • header.tsx: simulate a header component (in next samples this will include a nav bar).
  • aboutPage.tsx: page like component.

Code cleanup study

Current sample code base needs a good cleanup, I propose @algil to create first a list of enhancements, then we can break / group them by issues and proceed with the cleanup task.

About the list to be generated, I would propose something like:

  • Enhancementes that must be applied:
    • Field name FireValidationFieldValueChange: wrong name it just updates ui it should be FireFieldValueChange
    • Remove imports that are not being used (e.g. memberapi in reducers).
    • (...) <-- @algil to create the whole list
  • Enhancements that needs discussion set an standard and then be implemented / set coding standard rule:
    • Imports, should we remove the "default" and use always {} ?
    • (...)

A later stage will be to configure tslinter

To complete this task you can answer in the task listing the enhancementes in a single comment.

Create html structure for the about page

Let's create a nice looking structure that will display a summary of the sample being implemented, proposal:

Sample title

_Short description _

Highlights

  • File: description

Any extra info e.g. diagram

Let's start with sample 11, spinner (this is just an idea, fulfill it with the components / clasess real names)
#11 Spinner async

In this sample we are going to show a spinner (busy indicator) whenever one or more ajax request are in progress.

Highlights

The most interesting parts worth to take a look:

  • Components:
    • Members Page: just fire two async request (gitHub json API), member and repositories belonging to a given organization.
    • Spinner: check the http reducers state values to hide / show the spinner.
  • Reducers
    • Http Reducer: Takes care of handling httpCallStarted and httpCallCompleted actions, updating the show spinner props (internally counts the number of requests that are in progress).
  • Actions:
    • Load action: member page trigger this actions to request async data.
    • httpCallStarted / httpCallCompleted: this two actions notify HttpReducer whenever an ajax request has been fired or completed.
  • Classes:
    • MemberAPI: fake member API (implemented two methods that request real json calls to github api to retrieve list of members and list of repos from a given organizations), this member API makes use of an http helper class we have created.
    • http: Wraps a $ajax.getjson request and takes care of notifying (dispatching an action) whenever an ajax call has been fired, and has been completed.

Create redux saga sample

Start from sample 10 (async thunk) and port it to sagas.

Grab the opportunity to rename some action name (request_START, request_Completed)...

Remove tbody, span warning

warning.js:45 Warning: validateDOMNesting(...): cannot appear as a child of . See Router > RouterContext > MembersPage > tbody > span.

This warning appears because:

<tbody> {
    this.state.members.map((member : memberEntity) =>
        <MemberRow key={member.id} member = {member}/>
    )
  }
</tbody>

It should be written like:

<tbody> 
   {
    this.state.members.map((member : memberEntity) =>
        <MemberRow key={member.id} member = {member}/>
    )
  }
</tbody>

Fix in samples:

  • 05 Presentational Comp
  • 06 AJAX Call
  • 07 Form
  • 08 ParamNavigation

MemberAPI should export default new MemberAPI

If not you create a new instance, member.id don't increment rigth, and allways it's 20.

export default new MemberAPI();

Proposal

import MemberEntity from './memberEntity'
import MembersMockData from './memberMockData'
import * as _ from 'lodash'
// Sync mock data API, inspired from:
// https://gist.github.com/coryhouse/fd6232f95f9d601158e4
class MemberAPI {
  private _idSeed : number;
// (...)
}

export default new MemberAPI();

Then we you want to use MemberAPI you don't need to make a "new" anymore, just call, e.g.: MemberAPI.SaveChanges(...)

Remove TR / TH warnings

Some sample of the Members page are not building the members table in proper HTML (missing TR)

          <table className="table">
            <thead>
              <th>
                Avatar
              </th>
              <th>
                Id
              </th>
              <th>
                Name
              </th>
            </thead>

Is missing, it should be

          <table className="table">
            <thead>
              <tr>
                <th>
                  Avatar
                </th>
                <th>
                  Id
                </th>
                <th>
                  Name
                </th>
              </tr>
            </thead>

Right now we get the follwing warning (console):

Warning: validateDOMNesting(...): cannot appear as a child of . See MembersPage > thead > th.

could you review the samples and apply the patch where applies.

MemberAPI should return single instance / static

Right now we are just making a "new" whenever we want to use this, we should make an export default o a "new instance"? or just declare it static? Check on this and come up with a solution.

Avoid webpack global install, use npm start

Let's avoid npm -g installs whenver is possible.

We should in all projects:

npm install webpack webpack-dev-server --save

And add an start script to package json

"scripts": {
    "start": "webpack",    
  },

By doing this we can just execute from command line:

npm start

Add this change in all samples, then update the global readme.md

Add steps to install and run the samples

We can base it on the other project ReactBoiler.

Prerequisites...

npm install
npm start

(...)

Indicate we are using atom as editor, we are checking for visual studio code to properly configure it.

Remove hack, canot use statelessComponent

Right now on the definition of

class MemberPage extends React.Component<Props, {}> {

We are using React.Component, we should be using React.StatelessComponent, if we make this change we get an error, we had to rollback to React.Component, and add an ugly hack when gluing the reducer:


// TODO: Hack to bypass the issue when declaring StateLessComponent
// Pending research here
var nonTypedMemberPage : any = MemberPage;

const ContainerMemberPage = connect(
                                   mapStateToProps
                                  ,mapDispatchToProps
                                )(nonTypedMemberPage)

We need to unsderstand what's going on here and how this could be fixed, found in stackoverflow that we should upgrade to typescript 1.8 in order to fix that done but no luck, maybe is just the tsd that is not well defined.

Call for contributors

Some months ago this project started as something internal... let's create some simple samples that cover react / redux / typescript scenarios that could serve as a guidance and reference in the future... now, we and other developers are using this repo as quick by sample guidance. We keep on adding more samples to it, but we have found that older samples need some updates / refactoring.

Tasks that we are planning:

  • Replace tsd and use typings on each sample.
  • Add better naming to actions.
  • Add a readme.md to each of the sample (explaining the sample and include an step by step guide to create them from default).
  • Better use of imports, casing and other details (code quality).
  • Introduce ts-linter.
  • Add more samples.
  • (...).

Are you interested in contributing into this project? If that's the case don't hesitate contacting us.

About page sample 00 Boiler plate

Proposal ( @nasdan to complete it):
#00 Boiler plate

In this sample we are going to setup the basic plumbing to "build" our project and launch it in a dev server. We are going to use: webpack, typescript.

In order to launch this project, follow this steps

TODO: Add all the steps here, npm install...
npm start

Then open your browser and navigate to: http://localhost:8080

Highlights

The most interesting parts worth to take a look:

  • Package.json: check packages installed.
  • Webpack config: check the build process and ts-loader to handle typescript).
  • tsd.json: typescript definitions.
  • src: javascript using imports.

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.