Git Product home page Git Product logo

peachtree-bank's Introduction

Why I choose reactjs lasted version instead of Angular lasted version.

I can develop this app using both of the reactjs library and the Angular framework (2 frameworks js most popular) but I choose reactjs because I would like apply RXJS to reactjs app to management global state, communication between components, instead of using Mobx, RecoilJs, Redux, Redux-toolkit, Redux-thunk, Redux-saga, Redux Observable middleware. I see redux we have to config very complex and abundant code, boring code for action creation, reducer, middleware...

I want to use RXJS to solve asynchronous actions, timers... and also resolve state management problem. RXJS we can smoothly apply in the Angular framework that I can smoothly apply in this project with chanel (I call it chanel - anyone who subscribes to the chanel will get whatever changed in this chanel).

Overview libraries using in the project ๐Ÿฎ

This uses some supporting plugins:

  • React Libraries (Main Platform): 'react', 'react-dom'.
  • React Router V4 (React Plugin): 'react-router', 'react-router-dom'.
  • RXJS - Reactive Extensions for JavaScript (handle side effect: asynchronous, timer, share data between components - state management...
  • Webpack (Bundling Module support to build project): 'webpack'
  • SASS - Pre-Processor: 'sass', 'node-sass'
  • Library UI: 'react-bootstrap',
  • react-toastify.

Guideline for focusing and developing to project

1. Using command line (CLI) in project

*Note: You can 'yarn' or 'npm' to work with this project.

Current time, we just use 'start' & 'build' to develop and pack modules in the project:

  • Build project for the production environment:
  npm run build    
  yarn run build 
  • Start project at dev environment:
  npm start
  yarn start

2. Structure of project

peachtree-bank
	|
	โ”œโ”€โ”€ README.md
	โ”œโ”€โ”€ package.json
	โ”œโ”€โ”€ public
	โ”œโ”€โ”€ build
	โ”œโ”€โ”€ src
	โ”‚ย ย  โ”œโ”€โ”€ app
	โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ App.tsx
	โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ app.scss
	โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ new-transfer
	โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ model-confirm
	โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ recent-transactions
	โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ content
	โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ search-sort-bar
	โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ shared
	โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ style-common.scss
	โ”‚ย ย  โ”œโ”€โ”€ assets
	โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ fonts
	โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ images
	โ”‚ย ย  โ”œโ”€โ”€ chanel
	โ”‚ย ย  โ”œโ”€โ”€ common
	โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ constants
	โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ enums
	โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ types
	โ”‚ย ย  โ”œโ”€โ”€ index.html
	โ”‚ย ย  โ””โ”€โ”€ services
	โ”œโ”€โ”€ tsconfig.json
	โ””โ”€โ”€ webpack

  • 2.1. tsconfig.json:
    File configures for typescript project such as compile decorator.

  • 2.2. package.json
    File contains all configurations of project (libs-dependencies, script-task, plugins...)

  • 2.3. build/ folder:
    It stores sources of project after building.

  • 2.4. public/ folder:
    It stores sources (css, data-resources, fonts, images, locales) of project after building at the dev environment.

  • 2.5. webpack/ file:
    It includes files using to build and start project.

  • 2.6. src/
    This is the main folder in project. You can develop anything in here. It separates to 5 sub-folders: common/ , assets/ , chanel/, service, app, app.tsx and index.tsx file

    • 2.6.1. common/ folder
      This includes constant, enum....

    • 2.6.2. assets/ folder
      This includes images, fonts....

    • 2.6.3. chanel/ folder
      This includes data share between components.

    • 2.6.4. service/ folder
      This includes all of apis.

    • 2.6.5. app/ folder
      This includes ts and scss files of component group by every feature.

      • 2.6.5.1. shared/ folder
        This includes common files, logic, component... which can re-use more than one time in project.
    • 2.6.6. app.tsx/ file
      App.tsx is a start-point to any process, and imported out of index.tsx to run project.

    • 2.6.7 index.tsx file
      This is the first file called from server after running project. All threads of project will begin from here.

3. Basic knowledge and how to apply to this project - chanel - state management

3.1: Create a chanel - to share data between components - we use Subject in RXJS to emit values to be multi-casted to many Observers.

  • To define a chanel.
  import { initialFilter } from './../common/constants/CommonConst';
  import { getTransactionsHistoryService } from '../services/getAccount.service';

  import { from, Subject } from 'rxjs';
  import { toast } from 'react-toastify';

  const subject = new Subject();
  const initialState = {
  	transactionsHistory: [],
  };

  let state = initialState;

  const transactionsHistoryChanel = {
  	subscribe: (setState: any) => subject.subscribe(setState),
  	getTransactionsHistory: (filter?: any) => {
  		if (!filter) {
  		filter = initialFilter;
  		}

  		from(getTransactionsHistoryService(filter)).subscribe((e: any) => {
  			state = {
  				...state,
  				transactionsHistory: e
  			};
  			subject.next(state);
  		});
  	},
  };

  export default transactionsHistoryChanel;

3.2: To use this chanel in a component - we subscribe the chanel to get data whenever it's changed.

  import React, { useLayoutEffect, useState } from 'react';
  import transactionsHistoryChanel from '../../../chanel/transactions-history.chanel';

  function Content() {

  	const [state, setState] = useState<any>();

  	useLayoutEffect(() => {
  		transactionsHistoryChanel.subscribe(setState);
  	}, []);
  }

  export default Content;

3.3: Emit value via function getTransactionsHistory to search or sort transactions history.

  import React, { useEffect, useState } from 'react';
  import transactionsHistoryChanel from '../../../chanel/transactions-history.chanel';


  function SearchSortBar() {

  	const [filter, setFilter] = useState(initialFilter);

  	useEffect(() => {
  		transactionsHistoryChanel.getTransactionsHistory(filter);
  	}, [filter]);
  }

  export default SearchSortBar;

View more:

4. Run project

  1. npm run start (port 4200)
  2. Start Nodejs server (default port 4200, Can change port at the webpack devServer port).
  3. Open web browser with url: http://your_ip:4200/

5. Note commit in project

Don't commit these paths folder and file in the project. Because, they will auto generate when build

\peachtree-bank\target
\peachtree-bank\build
\peachtree-bank\package-lock.json
\peachtree-bank\yarn-lock.json
\peachtree-bank\yarn.lock
\peachtree-bank\yarn-error.log
\peachtree-bank\debug.log

peachtree-bank's People

Contributors

nhutlbuit avatar

Watchers

James Cloos 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.