Our GCC is a project developed by React that makes it painless to create interactive UIs. Design simple views for each state in your application, and React will update and render just the right components when your data changes.And there is a picture that we can understand React better:

Today, we will show you all middleware in GCC and describing some important middleware:

Middleware in GCC
Intention
react-dom              

The react-dom package provides DOM-specific methods that can be used at the top level of your app.

we can use it like as:

import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>Hello world</h1>
, document.getElementById('app'));
prop-types

The role of the library is to react with proptypes type detection. As the name suggests prop-types is the react component props object in the type of detection, because props is the flow of data flow pipeline, we can easily monitor the prop-types in most of the variables in the variable type.propTypes can be used to detect all data types of variables, including the basic type of string, boolean, number, and the reference type of object, array, function, and even ES6 new symbol type, such as:

import PropTypes from 'prop-types';
yourComponent.propTypes = {
prop1: PropTypes.object,
prop2: PropTypes.func,
prop3: PropTypes.array,
prop1: PropTypes.bool,
prop2: PropTypes.string,
prop3: PropTypes.number,
};

In addition, we can use 3 method to do more detaction:

  1. oneOfType: to receive parameters is an array, the array element is the type of data you want to detect, such as:

    yourComponent.propTypes = {
    prop1:PropTypes.oneOfType(
    [PropTypes.string,PropTypes.number]
    )
  2. oneOf: to receive parameters is an array, the array element is the value of the variable you want to pass, such as:

    yourComponent.propTypes = {
    prop1:PropTypes.oneOf(
    [12,13]
    )
    }
  3. arrayOf, objectOf: arrayOf receives a parameter, which is the data type of the specified array element. The objectOf received parameter is the data type of the attribute
  4. shape: The shape method is better than arrayOf and objectOf because the data types of arrayOf and objectOf are forcibly specified, but usually there should be a number of different types of attributes in an object, which is what the shape is to do, such as:
    yourComponent.propTypes = {
    prop1: PropTypes.shape({
    prop1_1: PropTypes.func,
    prop1_2: PropTypes.bool,
    prop1_3: PropTypes.string,
    }),
    }

    More Details

redux

React is just an abstract layer of the DOM, not a complete solution for Web applications. When we use React to build large applications, the communication between components becomes cumbersome. Redux is to solve this problem.Redux design is very simple, two sentences.

  1. Web application is a state machine, the view and the state is one to one correspondence.
  2. all the state, stored in an object inside.

Store is where to save the data, you can think of it as a container. The entire application can only have one Store.
Redux provides createStore this function, used to generate Store, such as:

import { createStore } from 'redux';
const store = createStore(fn);

And Store provide 3 methods:

  1. store.getState() – Get a snapshot of the current time Store.
  2. store.dispatch() – Send a atcion to tell Store to deal with.
  3. store.subscribe() – Store allows you to set the listening function using the store.subscribe method, which is executed automatically once State has changed.

The following is a simple createStore implementation, we can better understand the Store:

const createStore = (reducer) => {
let state;
let listeners = []; const getState = () => state; const dispatch = (action) => {
state = reducer(state, action);
listeners.forEach(listener => listener());
}; const subscribe = (listener) => {
listeners.push(listener);
return () => {
listeners = listeners.filter(l => l !== listener);
}
}; dispatch({}); return { getState, dispatch, subscribe };
};

Another, Redux provide a method of combineReducers for Reducer's split. You just define the child Reducer functions, and then use this method to combine them into a large Reducer.

More Details

react-redux

The react-redux component is actually redux the author's custom library for the reactor and react-redux divides all components into two categories: UI components and container components.In short, the UI component is responsible for the rendering of the UI, and the container component is responsible for managing the data and logic.

React-Redux provides a connect method for generating container components from UI components, such as:

import { connect } from 'react-redux'

const containerComponent = connect(
mapStateToProps,
mapDispatchToProps
)(UIComponent)

In the above code,

  1. mapStateToProps is a function. It is the role of its name as it is, from the (external) state object (UI component) props object mapping;
  2. mapDispatchToProps is the second argument to the connect function that is used to create a mapping of the UI component's parameters to the store.dispatch method. In other words, it defines which users should operate as Action, pass to the Store. It can be a function or an object.

Source Code

redux-form

redux-form works with React Redux to enable an html form in React to use Redux to store all of its state.

The diagram below represents the simplified data flow:

Note: redux-form has been completely rewritten for v6, because of a fundamental design change.

More Details

classnames

A simple JavaScript utility for conditionally joining classNames together.

In React, one of its primary use cases is to make dynamic and conditional className props simpler to work with (especially more so than conditional string manipulation). So where you may have the following code to generate a classNameprop for a <button> in React:

var Button = React.createClass({
// ...
render () {
var btnClass = 'btn';
if (this.state.isPressed) btnClass += ' btn-pressed';
else if (this.state.isHovered) btnClass += ' btn-over';
return <button className={btnClass}>{this.props.label}</button>;
}
});

You can express the conditional classes more simply as an object:

var classNames = require('classnames');

var Button = React.createClass({
// ...
render () {
var btnClass = classNames({
btn: true,
'btn-pressed': this.state.isPressed,
'btn-over': !this.state.isPressed && this.state.isHovered
});
return <button className={btnClass}>{this.props.label}</button>;
}
});

More Details

Other small middle-ware

react-select、react-tabs、d3

React

middlewares in GCC的更多相关文章

  1. VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

    1.问题描述 由于安装VS15 Preview 5,搞的系统由重新安装一次:在用vscdoe编译go语言时,出现以下问题: # odbcexec: "gcc": executabl ...

  2. GCC学习(1)之MinGW使用

    GCC学习(1)之MinGW使用 因为后续打算分享一些有关GCC的使用心得的文章,就把此篇当作一个小预热,依此来了解下使用GNU工具链(gcc.gdb.make等)在脱离IDE的情况下如何开发以及涉及 ...

  3. 使用 GCC 和 GNU Binutils 编写能在 x86 实模式运行的 16 位代码

    不可否认,这次的标题有点长.之所以把标题写得这么详细,主要是为了搜索引擎能够准确地把确实需要了解 GCC 生成 16 位实模式代码方法的朋友带到我的博客.先说一下背景,编写能在 x86 实模式下运行的 ...

  4. [异常解决] How to build a gcc toolchain for nRF51 on linux (very detailed!!!)

    1.Install gcc-arm-none-eabi https://devzone.nordicsemi.com/tutorials/7/This link shows that developm ...

  5. CentOS 6.6 升级GCC G++ (当前最新版本为v6.1.0) (完整)

    ---恢复内容开始--- CentOS 6.6 升级GCC G++ (当前最新GCC/G++版本为v6.1.0) 没有便捷方式, yum update....   yum install 或者 添加y ...

  6. GCC 预处理、编译、汇编、链接..

    1简介 GCC 的意思也只是 GNU C Compiler 而已.经过了这么多年的发展,GCC 已经不仅仅能支持 C 语言:它现在还支持 Ada 语言.C++ 语言.Java 语言.Objective ...

  7. 用gcc进行程序的编译

    在Linux系统上,一个档案能不能被执行看的是有没有可执行的那个权限(x),不过,Linux系统上真正认识的可执行文件其实是二进制文件(binary program),例如/usr/bin/passw ...

  8. gcc/linux内核中likely、unlikely和__attribute__(section(""))属性

    查看linux内核源码,你会发现有很多if (likely(""))...及if (unlikely(""))...语句,这些语句其实是编译器的一种优化方式,具 ...

  9. Ubuntu 14.04 LTS 下升级 gcc 到 gcc-4.9、gcc-5 版本

    如果没记错的话,阿里云ECS上的Ubuntu也是LTS版本. 如果还在使用较旧版本的Ubuntu,或者是Ubuntu LTS,那么我们是很难体验新版gcc的.怎么办呢? 我们或许可以自己去编译用旧版本 ...

随机推荐

  1. 关于Class对象、类加载机制、虚拟机运行时的内存布局的全面解析和推测

    简介: 本文是对Java的类加载机制,Class对象,反射原理等相关概念的理解.验证和Java虚拟机中内存布局的一些推测.本文重点讲述了如何理解Class对象以及Class对象的作用. 欢迎探讨,如有 ...

  2. Python实战之Selenium自动化测试web刷新FW

    需求:将手工登录,手工刷新服务器的FW转化为Python+Selenium实现自动化操作. 1.创建用户表,实现数据与脚本分离.需要读取模块. 2.自动化刷新FW. 不说话,直接上代码: 1userd ...

  3. zoj 1874 水题,输出格式大坑

    Primary Arithmetic Time Limit: 2 Seconds      Memory Limit: 65536 KB Children are taught to add mult ...

  4. ZOJ1171

    错误代码先放这 #include<cstdio> #include<cstdlib> #include<iostream> #include<cstring& ...

  5. ZOJ 1489 HDU1395 2^x mod n = 1 数学

    2^x mod n = 1 Time Limit: 2 Seconds      Memory Limit:65536 KB Give a number n, find the minimum x t ...

  6. Collection和Map的默认扩容参数

    初始大小:调用无参构造函数时默认的容量 加载因子:超过 (当前容量*加载因子) 时会进行扩容 扩容因子:扩容时增加的容量为 (当前容量*扩容因子)        容器         初始容量    ...

  7. JVM性能调优,GC

    刚刚做完了一个项目的性能测试,“有幸”也遇到了内存泄露的案例,所以在此和大家分享一下. 主要从以下几部分来说明,关于内存和内存泄露.溢出的概念,区分内存泄露和内存溢出:内存的区域划分,了解GC回收机制 ...

  8. 【特效】jquery选项卡插件,页面多个选项卡统一调用

    把选项卡整合了一下,写成个插件,这样可以整个站,或整个页面有多个选项卡时,统一调用.代码的具体注意事项已经写进注释了.用于js获取元素的class名称必须有,选项卡本身的样式,另再取一个名字来设置(本 ...

  9. Iframe父子窗口之间的跨域事件调用和传值

    实现方案1:location.hash传值 父页面:parent.html(所在域:www.parent.com) 子页面:child.html(所在域:www.child.com) 要实现父子页面双 ...

  10. Python学习笔记(四)

    Python学习笔记(四) 作业讲解 编码和解码 1. 作业讲解 重复代码瘦身 # 定义地图 nav = {'省略'} # 现在所处的层 current_layer = nav # 记录你去过的地方 ...